Client¶
High-level sync and async clients that wrap the GoPro API with search pagination, asset selection, and file download helpers.
GoProClient¶
gopro_api.client.GoProClient(access_token: str | None = None, timeout: float = 10.0, *, page_size: int = 1000, max_items: int = 1, prefer_height: int | None = None, prefer_width: int | None = None)
¶
High-level sync client for GoPro cloud media.
Wraps GoProAPI via composition and adds search pagination, asset
selection, and file download helpers. Use as a context manager; the
underlying HTTP session is opened and closed for you.
Create a sync high-level client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
access_token
|
str | None
|
|
None
|
timeout
|
float
|
Per-request HTTP timeout in seconds (API and CDN fetches). |
10.0
|
page_size
|
int
|
Default page size for |
1000
|
max_items
|
int
|
Maximum rows returned by |
1
|
prefer_height
|
int | None
|
Preferred video height in pixels for |
None
|
prefer_width
|
int | None
|
Preferred video width in pixels for |
None
|
Source code in gopro_api/client.py
__enter__() -> 'GoProClient'
¶
__exit__(*exc: object) -> None
¶
search(params: GoProMediaSearchParams) -> GoProMediaSearchResponse
¶
Run a single media search request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
GoProMediaSearchParams
|
Query parameters for |
required |
Returns:
| Type | Description |
|---|---|
GoProMediaSearchResponse
|
Parsed search response. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If used outside |
HTTPError
|
When the HTTP status is not successful. |
ValidationError
|
If the JSON body does not match the model. |
Source code in gopro_api/client.py
download(media_id: str) -> GoProMediaDownloadResponse
¶
Fetch download metadata for one media id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
media_id
|
str
|
Cloud library identifier. |
required |
Returns:
| Type | Description |
|---|---|
GoProMediaDownloadResponse
|
Parsed download metadata response. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If used outside |
HTTPError
|
When the HTTP status is not successful. |
ValidationError
|
If the JSON body does not match the model. |
Source code in gopro_api/client.py
check_auth() -> GoProAuthStatus
¶
Verify that the configured access token is accepted by the API.
Returns:
| Type | Description |
|---|---|
GoProAuthStatus
|
Structured authentication status from the underlying API client. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If used outside |
Source code in gopro_api/client.py
iter_nonempty_search_pages(start_date: datetime, end_date: datetime, *, per_page: int | None = None, start_page: int = 1) -> Iterator[GoProMediaSearchResponse]
¶
Yield search result pages until one returns an empty _embedded.media.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_date
|
datetime
|
Capture range start (inclusive semantics per API). |
required |
end_date
|
datetime
|
Capture range end. |
required |
per_page
|
int | None
|
Items per page; defaults to |
None
|
start_page
|
int
|
First page number to request (1-indexed). |
1
|
Yields:
| Type | Description |
|---|---|
GoProMediaSearchResponse
|
Each non-empty |
Source code in gopro_api/client.py
list_media_items(start_date: datetime, end_date: datetime) -> list[GoProMediaSearchItem]
¶
Collect media rows across pages up to max_items.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_date
|
datetime
|
Capture range start. |
required |
end_date
|
datetime
|
Capture range end. |
required |
Returns:
| Type | Description |
|---|---|
list[GoProMediaSearchItem]
|
Up to |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If used outside |
HTTPError
|
When any underlying |
ValidationError
|
If any underlying |
Source code in gopro_api/client.py
get_download_url(media_items: list[GoProMediaSearchItem]) -> dict[str, DownloadAsset]
¶
Resolve download assets for each search row.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
media_items
|
list[GoProMediaSearchItem]
|
One or more media rows (typically from search). |
required |
Returns:
| Type | Description |
|---|---|
dict[str, DownloadAsset]
|
Merged mapping of output filename to file or variation metadata. |
Raises:
| Type | Description |
|---|---|
NoVariationsError
|
For video items with no variations. |
RuntimeError
|
If used outside |
HTTPError
|
When any underlying |
ValidationError
|
If any underlying |
Source code in gopro_api/client.py
download_url_to_path(url: str, dest_path: str) -> None
¶
Download a CDN URL to a local path.
Uses a one-shot requests.get because CDN hosts differ from
api.gopro.com.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
Fully qualified HTTPS URL from download metadata. |
required |
dest_path
|
str
|
Filesystem path for the response body. |
required |
Raises:
| Type | Description |
|---|---|
HTTPError
|
When the HTTP status is not successful. |
OSError
|
If the destination cannot be written. |
Source code in gopro_api/client.py
AsyncGoProClient¶
gopro_api.client.AsyncGoProClient(access_token: str | None = None, timeout: float = 10.0, *, page_size: int = 1000, max_items: int = 1, prefer_height: int | None = None, prefer_width: int | None = None)
¶
High-level async client for GoPro cloud media.
Wraps AsyncGoProAPI via composition and mirrors GoProClient using
async/await and aiohttp. Use as an async context manager; the
underlying aiohttp.ClientSession is opened and closed for you.
Create an async high-level client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
access_token
|
str | None
|
|
None
|
timeout
|
float
|
Total |
10.0
|
page_size
|
int
|
Default page size for |
1000
|
max_items
|
int
|
Maximum rows returned by |
1
|
prefer_height
|
int | None
|
Preferred video height in pixels for |
None
|
prefer_width
|
int | None
|
Preferred video width in pixels for |
None
|
Source code in gopro_api/client.py
__aenter__() -> 'AsyncGoProClient'
async
¶
Enter the underlying AsyncGoProAPI context.
Returns:
| Type | Description |
|---|---|
'AsyncGoProClient'
|
|
__aexit__(*exc: object) -> None
async
¶
search(params: GoProMediaSearchParams) -> GoProMediaSearchResponse
async
¶
Run a single media search request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
GoProMediaSearchParams
|
Query parameters for |
required |
Returns:
| Type | Description |
|---|---|
GoProMediaSearchResponse
|
Parsed search response. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If used outside |
ClientResponseError
|
When |
ValidationError
|
If the JSON body does not match the model. |
Source code in gopro_api/client.py
download(media_id: str) -> GoProMediaDownloadResponse
async
¶
Fetch download metadata for one media id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
media_id
|
str
|
Cloud library identifier. |
required |
Returns:
| Type | Description |
|---|---|
GoProMediaDownloadResponse
|
Parsed download metadata response. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If used outside |
ClientResponseError
|
When |
ValidationError
|
If the JSON body does not match the model. |
Source code in gopro_api/client.py
check_auth() -> GoProAuthStatus
async
¶
Verify that the configured access token is accepted by the API.
Returns:
| Type | Description |
|---|---|
GoProAuthStatus
|
Structured authentication status from the underlying API client. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If used outside |
Source code in gopro_api/client.py
iter_nonempty_search_pages(start_date: datetime, end_date: datetime, *, per_page: int | None = None, start_page: int = 1) -> AsyncIterator[GoProMediaSearchResponse]
async
¶
Yield search pages until one returns an empty _embedded.media.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_date
|
datetime
|
Capture range start (inclusive semantics per API). |
required |
end_date
|
datetime
|
Capture range end. |
required |
per_page
|
int | None
|
Items per page; defaults to |
None
|
start_page
|
int
|
First page number to request (1-indexed). |
1
|
Yields:
| Type | Description |
|---|---|
AsyncIterator[GoProMediaSearchResponse]
|
Each non-empty |
Source code in gopro_api/client.py
list_media_items(start_date: datetime, end_date: datetime) -> list[GoProMediaSearchItem]
async
¶
Collect media rows across pages up to max_items.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_date
|
datetime
|
Capture range start. |
required |
end_date
|
datetime
|
Capture range end. |
required |
Returns:
| Type | Description |
|---|---|
list[GoProMediaSearchItem]
|
Up to |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If used outside |
ClientResponseError
|
When any underlying |
ValidationError
|
If any underlying |
Source code in gopro_api/client.py
get_download_url(media_items: list[GoProMediaSearchItem]) -> dict[str, DownloadAsset]
async
¶
Resolve download assets for each search row in parallel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
media_items
|
list[GoProMediaSearchItem]
|
One or more media rows (typically from search). |
required |
Returns:
| Type | Description |
|---|---|
dict[str, DownloadAsset]
|
Merged mapping of output filename to file or variation metadata. |
Raises:
| Type | Description |
|---|---|
NoVariationsError
|
For video items with no variations. |
RuntimeError
|
If used outside |
ClientResponseError
|
When any underlying |
ValidationError
|
If any underlying |
Source code in gopro_api/client.py
download_url_to_path(url: str, dest_path: str) -> None
async
¶
Download a CDN URL to a local path.
Opens a dedicated aiohttp.ClientSession without base_url so CDN
hosts work. The body is read fully into memory, then written via
asyncio.to_thread.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
Fully qualified HTTPS URL from download metadata. |
required |
dest_path
|
str
|
Filesystem path for the response body. |
required |
Raises:
| Type | Description |
|---|---|
ClientResponseError
|
When |
OSError
|
If the destination cannot be written. |