Skip to main content

Python SDK for Signet — OAuth 2.0 authentication and token management

Project description

Signet Python SDK

PyPI Python CI Trivy License

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

from signet import authenticate

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

print(f"Access token: {token.access_token}")

Async Usage

from signet import async_authenticate

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

Client Credentials (M2M)

from signet.discovery.client import DiscoveryClient
from signet.oauth import OAuthClient
from signet.clientcreds import TokenSource, BearerAuth
import httpx

disco = 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 request
with httpx.Client(auth=BearerAuth(ts)) as http:
    resp = http.get("https://api.example.com/data")

Middleware

FastAPI

from fastapi import FastAPI, Depends
from signet.middleware.fastapi import BearerAuth
from signet.middleware.models import TokenInfo

app = FastAPI()
auth = BearerAuth(oauth_client)

@app.get("/protected")
async def protected(info: TokenInfo = Depends(auth)):
    return {"user": info.user_id}

Flask

from flask import Flask
from signet.middleware.flask import bearer_auth, get_token_info

app = Flask(__name__)

@app.route("/protected")
@bearer_auth(oauth_client)
def protected():
    info = get_token_info()
    return {"user": info.user_id}

Examples

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

File Description
01_user_login.py Interactive user login — auto-selects browser or device code flow
02_client_credentials.py M2M service authentication with auto-cached tokens
03_fastapi_server.py FastAPI server with Bearer token validation and scope enforcement
04_async_login.py Async 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

go_signet-1.0.0.tar.gz (96.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

go_signet-1.0.0-py3-none-any.whl (34.4 kB view details)

Uploaded Python 3

File details

Details for the file go_signet-1.0.0.tar.gz.

File metadata

  • Download URL: go_signet-1.0.0.tar.gz
  • Upload date:
  • Size: 96.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for go_signet-1.0.0.tar.gz
Algorithm Hash digest
SHA256 6900e8933ce29ae75bb625b50f5cef6f98caa02b65c3150e851973f3beb336fb
MD5 58cfc262687c2bb9135f15fa87c1952d
BLAKE2b-256 c22eb5175bb66bd57aa1c440d328186eb3f7ab53c9a15005fad6d584d9f85a90

See more details on using hashes here.

Provenance

The following attestation bundles were made for go_signet-1.0.0.tar.gz:

Publisher: release.yml on go-signet/sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file go_signet-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: go_signet-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 34.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for go_signet-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e0b1973151df70967ae29dfb30b4a1ae912652e58363bba026a650ddc3bb748a
MD5 dc1c4322f90813a5fde8ae204afaaa0f
BLAKE2b-256 d42a6a5b97c66522cd6656932b01b63948e9c4d18dfb9a88a14504b22d0d1b0a

See more details on using hashes here.

Provenance

The following attestation bundles were made for go_signet-1.0.0-py3-none-any.whl:

Publisher: release.yml on go-signet/sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page