Sources¶
client.sources: /api/v1/sources/...
Bases: Resource
Sources: the files uploaded or synced for a user, and the activities made from them.
Every activity carries the source_id of the file it was made from, and one file can
make several activities. Activities are deleted with their source:
client.sources.delete(activity.source_id).
delete(source_id)
¶
Deletes a source and every activity made from it.
Endpoint: DELETE /api/v1/sources/{source_id}
This is how an activity is deleted: there is no endpoint for a single activity. One
file can make several activities, and all of them are deleted, permanently: retrieve
the source first and check its activity_ids. Each deleted activity fires
activity_deleted.
An app can delete only the files it uploaded. The user, with a token of their own, can delete any of their sources. For a source synced from a platform, the activities stay deleted unless the platform sends them again: when the athlete changes the activity there, or when the integration is reconnected.
Parameters:
-
source_id(str) –The source's ID, for example an activity's
source_id.
Raises:
-
SweatStackNotFoundError–If the source does not exist, or the token may not delete it: the API answers both with 404. A retry after a lost response also gets 404, for a delete that succeeded.
-
SweatStackAPIError–If the API request fails for any other reason.
Examples:
from sweatstack import Client
client = Client()
activity = client.activities.retrieve("act_123")
source = client.sources.retrieve(activity.source_id)
print(f"Deleting {source.filename}: activities {source.activity_ids}")
client.sources.delete(source.id)
delete_relayed(*, external_id)
¶
Deletes a file your app relayed, by its own ID, and every activity made from it.
Endpoint: DELETE /api/v1/sources
For an app that uploaded the file with activities.upload(..., external_id=...):
for example, when the platform it came from deleted the activity, or the athlete asked
you to. Each deleted activity fires activity_deleted. Uploading a file with the
same external_id afterwards creates a new source.
Parameters:
-
external_id(str) –Your app's own ID for the file, as sent on upload.
Raises:
-
SweatStackNotFoundError–If your app relayed no file under this ID for the user. A retry after a lost response also gets 404, for a delete that succeeded.
-
SweatStackAPIError–If the API request fails for any other reason.
Examples:
from sweatstack import Client
client = Client()
client.sources.delete_relayed(external_id="1001")
list(*, status=None, writer=None, platform=None, created_after=None, created_before=None, limit=50, offset=0)
¶
Lists the user's sources, newest first.
Endpoint: GET /api/v1/sources
status filters on the stored status. A source still processing after 30 minutes
reads as "failed" with error code processing_timeout, and still matches
status="processing": that is how you find the uploads that never finished.
Parameters:
-
status(SourceStatus | str | None, default:None) –Only sources with this status:
"processing","processed"or"failed". -
writer(WriterKind | str | None, default:None) –Only sources written by
"athlete","application"or"sweatstack"(SweatStack's own sync of a connected platform). -
platform(str | None, default:None) –Only sources from this platform:
"garmin_connect","strava", ... -
created_after(datetime | None, default:None) –Only sources created after this instant. Must be timezone-aware.
-
created_before(datetime | None, default:None) –Only sources created before this instant. Must be timezone-aware.
-
limit(int, default:50) –How many sources to return. The client pages through the endpoint until it has this many or there are no more.
-
offset(int, default:0) –How many of the newest matching sources to skip.
Returns:
-
list[SourceResponse]–list[SourceResponse]: Each with its
status,error,activity_ids, who -
list[SourceResponse]–wrote it and where it came from.
Raises:
-
TypeError–If
created_afterorcreated_beforeis adate, not adatetime. -
ValueError–If
created_afterorcreated_beforeis timezone-naive. -
SweatStackAPIError–If the API request fails.
Examples:
from datetime import datetime, timedelta, timezone
from sweatstack import Client
client = Client()
yesterday = datetime.now(timezone.utc) - timedelta(days=1)
stuck = client.sources.list(status="processing", created_after=yesterday)
retrieve(source_id)
¶
Retrieves a source: how its processing went, and the activities made from it.
Endpoint: GET /api/v1/sources/{source_id}
Use it to follow an upload until status is "processed" (with activity_ids)
or "failed" (with error), and to see which activities an activity's
source_id shares its file with.
Parameters:
-
source_id(str) –The source's ID, as returned by
activities.upload()or as an activity'ssource_id.
Returns:
-
SourceResponse(SourceResponse) –The source, with its
status,errorandactivity_ids.
Raises:
-
SweatStackNotFoundError–If the source does not exist or the user can't see it.
-
SweatStackAPIError–If the API request fails for any other reason.
Examples:
from sweatstack import Client
client = Client()
activity = client.activities.latest()
source = client.sources.retrieve(activity.source_id)
print(source.filename, source.activity_ids)