wger-api-client
Typed Python client for the wger REST API,
generated from the server's OpenAPI schema with
openapi-python-client.
Built on httpx, with a sync and an async call for every endpoint.
Note that this is still new, if you encounter any problems, please contact us.
Install
pip install wger-api-client
Versioning
The major and minor version indicate which wger release this client targets, so
2.6.x is meant for a 2.6 server. The patch version will probably be used to
indicate changes in this package itself, but that is not decided yet.
Since we try to keep the API as compatible as possible, an older client generally keeps working against a newer server, specially for stable endpoints such as the exercises. However, breaking changes are unavoidable, and it is recommended that you use the version that exactly matches the server you want to connect to.
Usage
Every endpoint has its own module under wger_api_client.api.<tag>, and each of
those exposes four functions:
| Function | Returns |
|---|---|
sync |
the parsed body, or None |
sync_detailed |
a Response with status code, headers and the parsed body |
asyncio |
as sync, awaitable |
asyncio_detailed |
as sync_detailed, awaitable |
With an API key from /user/api-key:
from wger_api_client import AuthenticatedClient
from wger_api_client.api.routine import routine_list
with AuthenticatedClient(
base_url="https://wger.de", token="<api key>", prefix="Token"
) as client:
page = routine_list.sync(client=client)
for routine in page.results:
print(routine.id, routine.name)
With a JWT access token, which is the same call with a different prefix:
client = AuthenticatedClient(
base_url="https://wger.de", token="<access token>", prefix="Bearer"
)
Unauthenticated endpoints, such as the exercises, work with the plain Client:
from wger_api_client import Client
from wger_api_client.api.exerciseinfo import exerciseinfo_list
with Client(base_url="https://wger.de") as client:
page = exerciseinfo_list.sync(client=client)
# without context manager
client = Client(base_url="https://wger.de", raise_on_unexpected_status=True)
page = exerciseinfo_list.sync(client=client)
By default a non-2xx response returns None from sync. Pass
raise_on_unexpected_status=True to the client to get an
errors.UnexpectedStatus exception instead.
Development
The generated package under wger_api_client/ is checked in, so that a schema
change shows up as a reviewable diff. Do not edit it by hand.
Updating the client after the server's API changed is two steps, refresh the schema and regenerate from it. The schema is read from a running wger instance, by default the upstream one at https://wger.de:
# 1. refresh schema/wger-openapi.yaml
uv run scripts/sync_schema.py [--base-url https://my.server]
# 2. regenerate the client from the refreshed schema
./scripts/generate.sh
uv run pytest
To pick up API changes that are not released yet, point it at a local instance
(./manage.py runserver in the server checkout) with --base-url or
$WGER_BASE_URL:
uv run scripts/sync_schema.py --base-url http://localhost:8000
Then commit both diffs together. A schema that moved without a regenerated client is exactly what CI rejects.
Two things to keep in mind when refreshing:
The instance must be backed by PostgreSQL, the way real deployments are. Django derives the bounds of its integer fields from the database backend, so the schema is backend-dependent. The default instance already satisfies this, so it only matters when syncing from a local checkout configured for SQLite.
Also note that the schema endpoint does not report the warnings that
./manage.py spectacular prints on the server side. Those warnings mean the schema
might be misdescribing the API somewhere, and the mistake gets baked into the
client, so check them in the server checkout whenever its serializers changed.
To verify without changing anything:
# does the committed client still match the committed schema?
./scripts/generate.sh --check
# has the server's schema moved since the snapshot was taken?
uv run scripts/sync_schema.py --check
tests/test_contract.py pins the parts of the contract that are easy to get
wrong when the calls are written by hand: which endpoints are read-only, which
methods each URL allows, the valid enum values and the writable field sets.
Contact
Feel free to contact us if you found this useful or if there was something that didn't behave as you expected. We can't fix what we don't know about, so please report liberally. If you're not sure if something is a bug or not, feel free to file a bug anyway.
- Discord: https://discord.gg/rPWFv6W
- Mastodon: https://fosstodon.org/@wger
- Issue tracker: https://github.com/wger-project/api-client/issues
License
Apache-2.0, see LICENSE.txt and NOTICE.
The wger server itself is AGPL-3.0-or-later. This client is licensed permissively so that it can be used as an ordinary dependency. The endpoint and field descriptions carried in the generated docstrings come from the server's source code and are attributed in the NOTICE file.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wger_api_client-2.6.1.tar.gz.
File metadata
- Download URL: wger_api_client-2.6.1.tar.gz
- Upload date:
- Size: 171.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b5c55d024c224aeacb5f554ab5f5c629f589cc95ad248fe35e66e546df73be7d
|
|
| MD5 |
d4d5babe1b6057e77515a21244c2deb8
|
|
| BLAKE2b-256 |
bfd645be60e906a88abc322a6b2ff434b50744d7fcdd28c7e55898282025aeb6
|
Provenance
The following attestation bundles were made for wger_api_client-2.6.1.tar.gz:
Publisher:
publish.yml on wger-project/api-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wger_api_client-2.6.1.tar.gz -
Subject digest:
b5c55d024c224aeacb5f554ab5f5c629f589cc95ad248fe35e66e546df73be7d - Sigstore transparency entry: 2450331990
- Sigstore integration time:
-
Permalink:
wger-project/api-client@71bab11e6f7794dfc7772e3026c5ade131bb26f0 -
Branch / Tag:
refs/tags/2.6.1 - Owner: https://github.com/wger-project
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@71bab11e6f7794dfc7772e3026c5ade131bb26f0 -
Trigger Event:
release
-
Statement type:
File details
Details for the file wger_api_client-2.6.1-py3-none-any.whl.
File metadata
- Download URL: wger_api_client-2.6.1-py3-none-any.whl
- Upload date:
- Size: 616.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c2fc4a6d5d45106c7946146e74bb73f6fe63d116973be7546d215dd47423e454
|
|
| MD5 |
f64c8e9dfbe7b8573db39c0a181a5194
|
|
| BLAKE2b-256 |
e461a5b5167398393153ef7116c4ff72047ec037fb324ca6b21cb95aa1443f28
|
Provenance
The following attestation bundles were made for wger_api_client-2.6.1-py3-none-any.whl:
Publisher:
publish.yml on wger-project/api-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wger_api_client-2.6.1-py3-none-any.whl -
Subject digest:
c2fc4a6d5d45106c7946146e74bb73f6fe63d116973be7546d215dd47423e454 - Sigstore transparency entry: 2450332075
- Sigstore integration time:
-
Permalink:
wger-project/api-client@71bab11e6f7794dfc7772e3026c5ade131bb26f0 -
Branch / Tag:
refs/tags/2.6.1 - Owner: https://github.com/wger-project
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@71bab11e6f7794dfc7772e3026c5ade131bb26f0 -
Trigger Event:
release
-
Statement type: