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.Clientobject 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.
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
Photo metadata for the activity upload response, if any.
- property is_complete: bool#
- property is_error: bool#
- property is_processing: 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.:
- 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:
stravalib.exc.TimeoutExceeded – If a timeout was specified and activity is still processing after timeout has elapsed.
stravalib.exc.ActivityUploadFailed – If the poll returns an error. The uploaded Activity object (fetched from server)