Skip to content

Repository files navigation

Signet Python SDK

PyPIPythonCITrivyLicense

Python SDK for Signet — OAuth 2.0 authentication and token management.

Installation

pip install go-signet

With framework support:

pip install go-signet[fastapi]
pip install go-signet[flask]
pip install go-signet[django]

Quick Start

fromsignetimportauthenticateclient, token=authenticate(
"https://auth.example.com",
"my-client-id",
scopes=["profile", "email"],
)
print(f"Access token: {token.access_token}")

Async Usage

fromsignetimportasync_authenticateclient, token=awaitasync_authenticate(
"https://auth.example.com",
"my-client-id",
scopes=["profile", "email"],
)

Client Credentials (M2M)

fromsignet.discovery.clientimportDiscoveryClientfromsignet.oauthimportOAuthClientfromsignet.clientcredsimportTokenSource, BearerAuthimporthttpxdisco=DiscoveryClient("https://auth.example.com")
meta=disco.fetch()
client=OAuthClient("my-service", meta.to_endpoints(), client_secret="secret")
ts=TokenSource(client, scopes=["api"])
# Auto-attaches Bearer token to every requestwithhttpx.Client(auth=BearerAuth(ts)) ashttp:
resp=http.get("https://api.example.com/data")

Middleware

FastAPI

fromfastapiimportFastAPI, Dependsfromsignet.middleware.fastapiimportBearerAuthfromsignet.middleware.modelsimportTokenInfoapp=FastAPI()
auth=BearerAuth(oauth_client)
@app.get("/protected")asyncdefprotected(info: TokenInfo=Depends(auth)):
return {"user": info.user_id}

Flask

fromflaskimportFlaskfromsignet.middleware.flaskimportbearer_auth, get_token_infoapp=Flask(__name__)
@app.route("/protected")@bearer_auth(oauth_client)defprotected():
info=get_token_info()
return {"user": info.user_id}

Examples

Ready-to-run examples are in the examples/ directory:

FileDescription
01_user_login.pyInteractive user login — auto-selects browser or device code flow
02_client_credentials.pyM2M service authentication with auto-cached tokens
03_fastapi_server.pyFastAPI server with Bearer token validation and scope enforcement
04_async_login.pyAsync user login via device code flow

Set the required environment variables, then run with uv:

export SIGNET_URL="https://auth.example.com"export CLIENT_ID="my-app"
uv run python examples/01_user_login.py

Development

make install # uv sync --all-extras
make test
make lint
make typecheck

License

MIT

Releases

Packages

Contributors

Languages