Brego SDK for Python
pip install brego
The partner connect flow for Python 3.8 or later, standard library only: PKCE and the authorise URL, code exchange, thread-safe refresh, revoke, API calls and webhook signature checks.
from brego import BregoPartnerClient, create_pkce, create_state
brego = BregoPartnerClient(client_id, client_secret, token_store)
verifier, challenge = create_pkce()
state = create_state()
url = brego.authorize_url(redirect_uri, state, challenge, scopes=["api:vehicle:read"])
# In your callback, after checking state:
connection = brego.exchange_code(code, redirect_uri, verifier)
info = brego.get_connection(connection.connection_id)
token_store needs get(connection_id), set(tokens) and
delete(connection_id), which revoke calls once the connection is ended. Store the newest
refresh token after every refresh. Refresh tokens are single use: if several
processes share the store, also give it with_lock(connection_id, fn), which
runs fn while holding a lock they all respect (a database row lock, for
example) and returns its result, so only one of them refreshes at a time. request refreshes the access token before it expires and
raises BregoApiError on a 403: if get_connection also fails, refresh
once, and ask the organisation to connect again if that fails too.
Pass API paths that start with a single / (for example /v1/vehicles); anything else is refused, so a connection's token is only ever sent to the configured API.
If two approvals of the same connection are exchanged at once, the later one replaces the earlier tokens. The SDK saves exchanged tokens one connection at a time and never over stored tokens that still work while the new ones are refused; the exchange then returns the stored tokens. If Brego can't be reached to check which tokens work, nothing is overwritten and the exchange raises BregoTokenCheckError, carrying the new tokens in tokens and the stored ones in stored. The code that produced the new tokens can't be used again, so keep whichever set works once you can check. If Brego refuses both sets, nothing is saved and the exchange raises BregoTokensRefusedError: the connection was approved again or revoked, so read its tokens from your store again.
If your token store cannot save tokens Brego has just issued, the SDK retries a few times and then raises BregoTokenStoreError, carrying the new tokens in tokens. The code or refresh token that produced them can't be used again, so save those tokens yourself.
Metadata
Release files for brego 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| brego-0.1.1.tar.gz | 9.8 kB | With provenance | Details for brego-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| brego-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for brego-0.1.1-py3-none-any.whl |
Total release size: 17.6 kB
Release files / brego-0.1.1.tar.gz
| Download URL | brego-0.1.1.tar.gz |
|---|---|
| Size | 9.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1eeb4e536ed5c2d1f1d2ef2b0163dff9de3a5687853ba2575b2b27e5a0f355ae
|
|
BLAKE2b-256 checksum How to use checksums |
c8fcd3612bd7198e41084e8dd7d9029ff44b44eeca9ee7bbca7d2dcdf2b88123
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.
Transparency logRelease files / brego-0.1.1-py3-none-any.whl
| Download URL | brego-0.1.1-py3-none-any.whl |
|---|---|
| Size | 7.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7d4486713d8cf6ed279ebcf4ff8c932b6e5263d0c238be1c348491b23840446c
|
|
BLAKE2b-256 checksum How to use checksums |
e5be3a24092503efd1aa50f61462d7c37d8eee02661b0520558f574fad044d82
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.
Transparency logSecurity for brego 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for brego-0.1.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.