GoProClient¶
gopro_sdk.client.GoProClient
¶
GoProClient(
target: str,
offline_mode: bool = True,
timeout_config: TimeoutConfig | None = None,
config_manager: CohnConfigManager | None = None,
wifi_ssid: str | None = None,
wifi_password: str | None = None,
)
Bases: HealthCheckMixin
GoPro client.
Design principles: - Supports offline mode (BLE only) and online mode (BLE+WiFi) - Offline mode is default (suitable for no WiFi or slow WiFi scenarios) - Composition over inheritance (holds command interface instances) - Delegation pattern (provides concise API) - Single responsibility (separates connection management and command execution)
Usage examples
Method 1 - Offline mode (default, BLE only, recommended for no WiFi or slow WiFi):
async with GoProClient("1332") as client: # offline_mode=True (default) ... await client.start_recording() # ✅ Control via BLE ... await client.set_date_time() # ✅ Sync time via BLE ... # await client.start_preview() # ❌ Not supported in offline mode
Method 2 - Online mode (BLE+WiFi, supports preview, download, etc.):
async with GoProClient("1332", offline_mode=False, wifi_ssid="MyWiFi", wifi_password="pass") as client: ... await client.start_recording() # ✅ Control via BLE ... await client.start_preview() # ✅ Preview via HTTP ... await client.download_media(...) # ✅ Download via HTTP
Method 3 - Dynamic mode switching:
async with GoProClient("1332") as client: # Start in offline mode ... await client.start_recording() # Via BLE ... # Switch to online mode when preview needed ... await client.switch_to_online_mode(wifi_ssid="MyWiFi", wifi_password="pass") ... await client.start_preview() # Preview now available
Method 4 - Camera already connected to WiFi (online mode, simplest):
async with GoProClient("1332", offline_mode=False) as client: ... await client.start_preview() # Directly use already connected WiFi
Initialize the client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
str
|
Camera serial number last four digits |
required |
offline_mode
|
bool
|
Whether to use offline mode (default True) - True: BLE only, no WiFi connection, no preview/download support (suitable for no WiFi scenarios) - False: BLE+WiFi, supports all features (requires WiFi network) |
True
|
timeout_config
|
TimeoutConfig | None
|
Timeout configuration |
None
|
config_manager
|
CohnConfigManager | None
|
COHN configuration manager |
None
|
wifi_ssid
|
str | None
|
WiFi SSID (optional, for automatic connection with async with, only effective in online mode) |
None
|
wifi_password
|
str | None
|
WiFi password (optional, used together with wifi_ssid) |
None
|
Note
- In offline mode, wifi_ssid/wifi_password will be ignored
- In online mode, if WiFi info is not provided, camera must already be connected to WiFi
- Can dynamically switch to online mode via switch_to_online_mode()
Raises:
| Type | Description |
|---|---|
ValueError
|
Provided wifi_ssid but not wifi_password |
Source code in src/gopro_sdk/client.py
Attributes¶
offline_mode
property
¶
Get current mode.
Returns:
| Type | Description |
|---|---|
bool
|
True for offline mode, False for online mode |
is_online
property
¶
Check if in online mode.
Returns:
| Type | Description |
|---|---|
bool
|
True for online mode, False for offline mode |
Functions¶
open
async
¶
Establish connection to the camera.
The connection method is determined by offline_mode: - Offline mode (offline_mode=True): BLE only, WiFi parameters ignored - Online mode (offline_mode=False): BLE + WiFi/COHN setup + HTTP initialization
Online mode workflow: 1. Connect via BLE 2. If WiFi credentials provided: - Query current camera WiFi status - If not connected or connected to different WiFi, reconfigure WiFi - If already connected to target WiFi, skip configuration 3. Attempt to load saved COHN credentials 4. If no credentials exist, configure COHN (camera auto-connects to remembered WiFi) 5. Initialize HTTP client (lazy connection)
WiFi parameter behavior (online mode only): - No WiFi credentials: Assumes camera is already on WiFi, directly configures COHN - If configuration fails, hints that WiFi credentials are needed - WiFi credentials provided: Actively connects to specified WiFi - Camera remembers WiFi password, next time can auto-connect with only SSID
Important notes: - Computer and camera must be on the same WiFi network, otherwise HTTP (COHN) connection will fail - Parameters passed to this method override constructor parameters - WiFi parameters are ignored in offline mode
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wifi_ssid
|
str | None
|
WiFi SSID (optional, only effective in online mode, overrides constructor parameter) |
None
|
wifi_password
|
str | None
|
WiFi password (optional, used with wifi_ssid) |
None
|
Raises:
| Type | Description |
|---|---|
BleConnectionError
|
BLE connection failed or WiFi/COHN configuration failed |
HttpConnectionError
|
HTTP connection failed (online mode only) |
ValueError
|
wifi_ssid provided but wifi_password missing |
Examples:
Offline mode:
>>> async with GoProClient("1332") as client: # offline_mode=True (default)
... await client.start_recording() # Works via BLE only
Online mode:
>>> async with GoProClient("1332", offline_mode=False, wifi_ssid="MyWiFi", wifi_password="pass") as client:
... await client.start_preview() # Works via HTTP
Source code in src/gopro_sdk/client.py
close
async
¶
Close all connections.
Source code in src/gopro_sdk/client.py
switch_to_online_mode
async
¶
Switch to online mode (dynamic switching).
If the client was initialized with offline mode, this method can switch to online mode to use features that require WiFi, such as preview and download.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wifi_ssid
|
str | None
|
WiFi SSID (optional, not needed if camera is already on WiFi) |
None
|
wifi_password
|
str | None
|
WiFi password (optional, used with wifi_ssid) |
None
|
Raises:
| Type | Description |
|---|---|
BleConnectionError
|
WiFi/COHN configuration failed |
ValueError
|
wifi_ssid provided but wifi_password missing |
Examples:
>>> async with GoProClient("1332") as client: # Default offline mode
... await client.start_recording() # Works via BLE
... # Switch to online mode when preview is needed
... await client.switch_to_online_mode(wifi_ssid="MyWiFi", wifi_password="pass")
... await client.start_preview() # Now preview works
Source code in src/gopro_sdk/client.py
set_shutter
async
¶
Control recording shutter.
Always uses BLE for more reliable recording control.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
enable
|
bool
|
True to start recording, False to stop recording |
required |
Source code in src/gopro_sdk/client.py
start_recording
async
¶
stop_recording
async
¶
set_preview_stream
async
¶
Control preview stream.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
enable
|
bool
|
True to enable, False to disable |
required |
port
|
int | None
|
Preview stream port (only needed when enabling) |
None
|
Raises:
| Type | Description |
|---|---|
OfflineModeError
|
This feature is not supported in offline mode |
Source code in src/gopro_sdk/client.py
start_preview
async
¶
Start preview stream.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
port
|
int
|
Preview stream port, default 8554 |
8554
|
Returns:
| Type | Description |
|---|---|
str
|
Preview stream URL (udp://ip:port) |
Raises:
| Type | Description |
|---|---|
HttpConnectionError
|
HTTP connection failed or unavailable |
GoproError
|
Camera rejected preview request |
Design philosophy
Direct attempt without polling - let operations fail fast with clear errors. Camera will return appropriate HTTP status codes if not ready (e.g., 409 if busy).
Source code in src/gopro_sdk/client.py
stop_preview
async
¶
tag_hilight
async
¶
Tag highlight (during recording).
Note
Always uses BLE command for more reliable operation.
get_camera_state
async
¶
Get camera status (raw format).
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Raw status dictionary in format: { "status": {"10": 0, "32": 1, ...}, "settings": {"2": 1, "3": 8, ...} } |
Note
Returns raw format (integer IDs). To parse as enum types,
use the get_parsed_state() method.
Raises:
| Type | Description |
|---|---|
OfflineModeError
|
This feature is not supported in offline mode |
Source code in src/gopro_sdk/client.py
get_parsed_state
async
¶
Get parsed camera status (enum format).
Returns:
| Type | Description |
|---|---|
dict[Any, Any]
|
Parsed status dictionary using StatusId/SettingId enums as keys, |
dict[Any, Any]
|
in format: { StatusId.ENCODING: False, StatusId.PREVIEW_STREAM: True, SettingId.VIDEO_RESOLUTION: VideoResolution.NUM_4K, ... } |
Examples:
>>> state = await client.get_parsed_state()
>>> if state[StatusId.ENCODING]:
... print("🔴 Camera is recording")
Source code in src/gopro_sdk/client.py
get_camera_info
async
¶
Get camera information.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Camera information dictionary |
Raises:
| Type | Description |
|---|---|
OfflineModeError
|
This feature is not supported in offline mode |
Source code in src/gopro_sdk/client.py
set_keep_alive
async
¶
Send keep-alive signal.
Raises:
| Type | Description |
|---|---|
OfflineModeError
|
This feature is not supported in offline mode |
set_date_time
async
¶
Set camera date and time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dt
|
datetime | None
|
Datetime object, defaults to current time |
None
|
tz_offset
|
int
|
Timezone offset (hours) |
0
|
is_dst
|
bool
|
Whether daylight saving time |
False
|
Note
Always uses BLE command for time sync (more reliable than HTTP)
Source code in src/gopro_sdk/client.py
get_date_time
async
¶
Get camera date and time.
Returns:
| Type | Description |
|---|---|
datetime
|
Datetime object |
Raises:
| Type | Description |
|---|---|
OfflineModeError
|
This feature is not supported in offline mode |
Source code in src/gopro_sdk/client.py
get_setting
async
¶
Get the value of specified setting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
setting_id
|
int
|
Setting ID |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Setting value |
Raises:
| Type | Description |
|---|---|
OfflineModeError
|
This feature is not supported in offline mode |
Source code in src/gopro_sdk/client.py
set_setting
async
¶
Modify the value of specified setting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
setting_id
|
int
|
Setting ID |
required |
value
|
int
|
Setting value |
required |
Raises:
| Type | Description |
|---|---|
OfflineModeError
|
This feature is not supported in offline mode |
Source code in src/gopro_sdk/client.py
get_preset_status
async
¶
Get preset status.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
include_hidden
|
bool
|
Whether to include hidden presets |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Preset status dictionary |
Raises:
| Type | Description |
|---|---|
OfflineModeError
|
This feature is not supported in offline mode |
Source code in src/gopro_sdk/client.py
load_preset
async
¶
Load specified preset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
preset_id
|
int
|
Preset ID |
required |
Note
Always uses BLE command for more reliable operation.
load_preset_group
async
¶
Load preset group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group_id
|
int
|
Preset group ID |
required |
Note
Always uses BLE command for more reliable operation.
Source code in src/gopro_sdk/client.py
set_digital_zoom
async
¶
Set digital zoom.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
percent
|
int
|
Zoom percentage (0-100) |
required |
Raises:
| Type | Description |
|---|---|
OfflineModeError
|
This feature is not supported in offline mode |
Source code in src/gopro_sdk/client.py
sleep
async
¶
Put camera to sleep.
Note
Uses BLE command which works in both online and offline modes.
reboot
async
¶
Reboot camera.
Note
Uses BLE command which works in both online and offline modes.
get_media_list
async
¶
Get list of all media files.
Returns:
| Type | Description |
|---|---|
list[MediaFile]
|
List of media files (MediaFile objects) |
Raises:
| Type | Description |
|---|---|
OfflineModeError
|
This feature is not supported in offline mode |
Source code in src/gopro_sdk/client.py
download_file
async
¶
download_file(
media_file: MediaFile | str,
save_path: str | Path,
progress_callback: Callable[[int, int], None]
| None = None,
) -> int
Download media file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
media_file
|
MediaFile | str
|
MediaFile object or file path |
required |
save_path
|
str | Path
|
Save path |
required |
progress_callback
|
Callable[[int, int], None] | None
|
Progress callback function (downloaded: int, total: int) -> None |
None
|
Returns:
| Type | Description |
|---|---|
int
|
Number of bytes downloaded |
Raises:
| Type | Description |
|---|---|
OfflineModeError
|
This feature is not supported in offline mode |
Source code in src/gopro_sdk/client.py
delete_file
async
¶
Delete single media file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
File path |
required |
Raises:
| Type | Description |
|---|---|
OfflineModeError
|
This feature is not supported in offline mode |
Source code in src/gopro_sdk/client.py
delete_all_media
async
¶
Delete all media files.
Raises:
| Type | Description |
|---|---|
OfflineModeError
|
This feature is not supported in offline mode |
get_media_metadata
async
¶
Get media file metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
File path |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Metadata dictionary |
Raises:
| Type | Description |
|---|---|
OfflineModeError
|
This feature is not supported in offline mode |
Source code in src/gopro_sdk/client.py
get_last_captured_media
async
¶
Get last captured media file information.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Media information dictionary |
Raises:
| Type | Description |
|---|---|
OfflineModeError
|
This feature is not supported in offline mode |
Source code in src/gopro_sdk/client.py
set_turbo_mode
async
¶
Enable/disable Turbo transfer mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
enable
|
bool
|
True to enable, False to disable |
required |
Raises:
| Type | Description |
|---|---|
OfflineModeError
|
This feature is not supported in offline mode |
Source code in src/gopro_sdk/client.py
start_webcam
async
¶
start_webcam(
resolution: int | None = None,
fov: int | None = None,
port: int | None = None,
protocol: str | None = None,
) -> dict[str, Any]
Start Webcam mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resolution
|
int | None
|
Resolution |
None
|
fov
|
int | None
|
Field of view |
None
|
port
|
int | None
|
Port |
None
|
protocol
|
str | None
|
Protocol |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Webcam response |
Raises:
| Type | Description |
|---|---|
OfflineModeError
|
This feature is not supported in offline mode |
Source code in src/gopro_sdk/client.py
stop_webcam
async
¶
Stop Webcam mode.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Webcam response |
Raises:
| Type | Description |
|---|---|
OfflineModeError
|
This feature is not supported in offline mode |
Source code in src/gopro_sdk/client.py
get_webcam_status
async
¶
Get Webcam status.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Webcam status dictionary |
Raises:
| Type | Description |
|---|---|
OfflineModeError
|
This feature is not supported in offline mode |
Source code in src/gopro_sdk/client.py
start_webcam_preview
async
¶
Start Webcam preview.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Webcam response |
Raises:
| Type | Description |
|---|---|
OfflineModeError
|
This feature is not supported in offline mode |
Source code in src/gopro_sdk/client.py
webcam_exit
async
¶
Exit Webcam mode.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Webcam response |
Raises:
| Type | Description |
|---|---|
OfflineModeError
|
This feature is not supported in offline mode |
Source code in src/gopro_sdk/client.py
get_webcam_version
async
¶
Get Webcam implementation version.
Returns:
| Type | Description |
|---|---|
str
|
Version string |
Raises:
| Type | Description |
|---|---|
OfflineModeError
|
This feature is not supported in offline mode |
Source code in src/gopro_sdk/client.py
reset_cohn
async
¶
Reset COHN configuration (clear certificate and recreate).
⚠️ Only use in these special cases: 1. Camera executed "Reset Network Settings" (certificate cleared) 2. Certificate expired (Root CA certificate valid for 1 year) 3. Certificate corrupted (validation failed) 4. Failed to get credentials and cannot be fixed via open()
✅ No need to call this method in normal cases: - Changed WiFi network → certificate still valid, only need to refresh IP - Router reset → certificate still valid, IP change handled automatically - Camera reboot → certificate still valid, COHN configuration applied automatically
Important
This method only resets the COHN certificate. It does NOT clear the camera's network cache. If experiencing COHN timeout due to cached network connections, you must manually reset via camera menu: Preferences → Connections → Reset Connections
Note: This operation clears existing certificate, camera must be connected to WiFi to complete configuration.
Returns:
| Type | Description |
|---|---|
CohnCredentials
|
New COHN credentials |
Raises:
| Type | Description |
|---|---|
BleConnectionError
|
Configuration failed (camera not connected to WiFi, etc.) |
Source code in src/gopro_sdk/client.py
configure_cohn
async
¶
Configure COHN (first-time configuration).
Returns:
| Type | Description |
|---|---|
CohnCredentials
|
Successfully configured COHN credentials |
Source code in src/gopro_sdk/client.py
setup_wifi
async
¶
setup_wifi(
ssid: str,
password: str,
timeout: float | None = None,
has_cohn_credentials: bool = False,
) -> None
Configure camera to connect to specified WiFi network.
Strategy (based on COHN credentials): 1. Has COHN credentials: Indicates camera connected before → Try RequestConnect first (no password) → Fallback to RequestConnectNew if failed (with password)
- No COHN credentials: First-time configuration → Directly use RequestConnectNew (with password)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ssid
|
str
|
WiFi SSID |
required |
password
|
str
|
WiFi password |
required |
timeout
|
float | None
|
Connection timeout (seconds), defaults to configured value |
None
|
has_cohn_credentials
|
bool
|
Whether has COHN credentials (passed by caller) |
False
|
Raises:
| Type | Description |
|---|---|
BleConnectionError
|
Connection failed |
Examples:
>>> async with GoProClient("1332") as client:
... await client.setup_wifi("MyHomeWiFi", "password123")
Source code in src/gopro_sdk/client.py
scan_wifi_networks
async
¶
Scan WiFi networks.
Note: Camera must be in AP mode (not connected to any network) to scan.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
float | None
|
Scan timeout (seconds), defaults to configured value |
None
|
Returns:
| Type | Description |
|---|---|
list[Any]
|
List of WiFi networks |
Raises:
| Type | Description |
|---|---|
BleConnectionError
|
Scan failed (possibly camera already connected to network) |
Source code in src/gopro_sdk/client.py
connect_to_wifi
async
¶
Connect to WiFi network.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ssid
|
str
|
WiFi SSID |
required |
password
|
str | None
|
WiFi password (can be None if already configured) |
None
|
timeout
|
float | None
|
Connection timeout (seconds), defaults to configured value |
None
|
Source code in src/gopro_sdk/client.py
Usage Examples¶
Basic Connection (Offline Mode)¶
import asyncio
from gopro_sdk import GoProClient
async def main():
# Default offline mode (BLE only)
async with GoProClient("1234") as client:
# Recording control
await client.start_recording()
await asyncio.sleep(5)
await client.stop_recording()
# Time sync
await client.set_date_time()
asyncio.run(main())
Online Mode (BLE + WiFi)¶
import asyncio
from gopro_sdk import GoProClient
async def main():
async with GoProClient(
"1234",
offline_mode=False,
wifi_ssid="YourWiFi",
wifi_password="YourPassword"
) as client:
# Get camera status
status = await client.get_camera_state()
print(f"Camera state: {status}")
# Start preview stream
stream_url = await client.start_preview()
print(f"Preview: {stream_url}")
asyncio.run(main())
Dynamic Mode Switching¶
async def main():
# Start in offline mode
async with GoProClient("1234") as client:
await client.start_recording()
await asyncio.sleep(5)
await client.stop_recording()
# Switch to online mode when needed
await client.switch_to_online_mode(
wifi_ssid="YourWiFi",
wifi_password="YourPassword"
)
# Now online features work
media = await client.get_media_list()
print(f"Found {len(media)} files")
With Custom Timeouts¶
from gopro_sdk import GoProClient
from gopro_sdk.config import TimeoutConfig
timeout_config = TimeoutConfig(
ble_connect_timeout=30.0,
http_request_timeout=60.0,
wifi_provision_timeout=120.0,
)
async with GoProClient(
"1234",
timeout_config=timeout_config,
offline_mode=False,
) as client:
await client.start_recording()
See Also¶
- MultiCameraManager - For controlling multiple cameras
- Commands - Available camera commands
- Connection - Connection management details