stravalib.client.ActivityUploader#

class stravalib.client.ActivityUploader(client: Client, response: dict[str, Any], raise_exc: bool = True)[source]#

The “future” object that holds information about an activity file upload and can wait for upload to finish, etc.

__init__(client: Client, response: dict[str, Any], raise_exc: bool = True) None[source]#

Initializes the instance with the given client, response, and optional exception flag.

Parameters:
  • client (stravalib.client.Client) – The stravalib.client.Client object that is handling the upload.

  • response (Dict[str,Any]) – The initial upload response.

  • raise_exc (bool) – Whether to raise an exception if the response indicates an error state. (default True)

Methods

poll()

Update internal state from polling strava.com.

raise_for_error()

Raise an appropriate exception if the upload encountered an error.

update_from_response(response[, raise_exc])

Updates internal state of object.

upload_photo(photo[, timeout])

Uploads a photo to the activity.

wait([timeout, poll_interval])

Wait for the upload to complete or to err out.

Attributes

is_complete

Check if the activity upload completed successfully.

is_error

Check if the activity upload encountered an error.

is_processing

Check if the activity upload is still being processed.

photo_metadata

Photo metadata for the activity upload response, if any.

property is_complete: bool#

Check if the activity upload completed successfully.

Returns:

True if the upload completed and an activity_id was assigned.

Return type:

bool

property is_error: bool#

Check if the activity upload encountered an error.

Returns:

True if an error occurred during upload.

Return type:

bool

property is_processing: bool#

Check if the activity upload is still being processed.

Returns:

True if the upload is still processing (no activity_id yet and no error).

Return type:

bool

property photo_metadata: Any#

Photo metadata for the activity upload response, if any. it contains a pre-signed uri for uploading the photo.

Notes

This is only available after the upload has completed. This metadata is only available for partner apps. If you have a regular / non partner related Strava app / account it will not work.

poll() None[source]#

Update internal state from polling strava.com.

Raises:

class – stravalib.exc.ActivityUploadFailed If poll returns an error.:

raise_for_error() None[source]#

Raise an appropriate exception if the upload encountered an error.

Raises:
update_from_response(response: dict[str, Any], raise_exc: bool = True) None[source]#

Updates internal state of object.

Parameters:
  • response (dict) – The response object (dict).

  • raise_exc (bool)

Raises:

stravalib.exc.ActivityUploadFailed – If the response indicates an error and raise_exc is True. Whether to raise an exception if the response indicates an error state. (default True)

upload_photo(photo: SupportsRead[bytes], timeout: float | None = None) None[source]#

Uploads a photo to the activity.

Parameters:
  • photo (bytes) – The file-like object to upload.

  • timeout (float, default=None) – The max seconds to wait. Will raise TimeoutExceeded

Notes

In order to upload a photo, the activity must be uploaded and processed.

The ability to add photos to activity is currently limited to partner apps & devices such as Zwift, Peloton, Tempo Move, etc… Given that the ability isn’t in the public API, neither are the docs

wait(timeout: float | None = None, poll_interval: float = 1.0) DetailedActivity[source]#

Wait for the upload to complete or to err out.

Will return the resulting Activity or raise an exception if the upload fails.

Parameters:
  • timeout (float, default=None) – The max seconds to wait. Will raise TimeoutExceeded exception if this time passes without success or error response.

  • poll_interval (float, default=1.0 (seconds)) – How long to wait between upload checks. Strava recommends 1s minimum.

Returns:

class

Return type:

stravalib.model.DetailedActivity

Raises: