Python helpers for talking to the google-authz service from popular web frameworks.
Project description
google-authz-client
High-level helpers for calling the google-authz service from Python APIs.
Version 0.5 ships framework integrations for FastAPI, Flask, and Django along with a shared HTTP client powered by httpx.
Installation
Pick the source that matches how you ship code. All of the examples show the fastapi extra, but feel free to swap in flask, django, or omit extras entirely.
From PyPI
pip install "google-authz-client[fastapi]"
This installs the latest published release and is the easiest option for production deployments.
From Git
pip install "google-authz-client[fastapi] @ git+https://github.com/example/google-authz-client.git@main"
Pin to a tag (for example @v0.5.0) when you want a reproducible build while still consuming code directly from Git.
Local Editable Install
pip install -e .[fastapi,flask,django,dev]
Use this when you are hacking on the library itself so your changes are reloaded without reinstalling. The extra groups are optional – install only what your framework needs.
Quick Start (FastAPI)
from fastapi import Depends, FastAPI
from google_authz_client.client import AsyncGoogleAuthzClient
from google_authz_client.fastapi import current_user, require_permission
client = AsyncGoogleAuthzClient()
app = FastAPI()
@app.get("/inventory")
async def read_inventory(
authz=Depends(current_user(client)),
_=Depends(require_permission("inventory:read", client=client)),
):
return {"subject": authz.subject, "perms": authz.permissions}
current_user discovers a token via cookies or the Authorization header, fetches the caller’s effective authorization, and raises HTTP 401/403 when missing or denied.
Flask Example
from flask import Flask
from google_authz_client.client import GoogleAuthzClient
from google_authz_client.flask import register_current_user_middleware, require_permission
app = Flask(__name__)
client = GoogleAuthzClient()
register_current_user_middleware(app, client)
@app.post("/inventory")
@require_permission("inventory:create", client=client)
def create_item():
return {"subject": flask.g.current_user.subject}
Django Middleware
# settings.py
from google_authz_client.client import GoogleAuthzClient
GOOGLE_AUTHZ_CLIENT = GoogleAuthzClient()
MIDDLEWARE.append("google_authz_client.django.GoogleAuthzMiddleware")
Configuration
Use GoogleAuthzSettings to load sensible defaults from environment variables:
from google_authz_client.config import GoogleAuthzSettings
settings = GoogleAuthzSettings()
client = settings.build_async_client()
Key settings include base_url, timeout_seconds, verify_tls, and shared_secret.
Development
Run linters and tests with:
pip install -e .[dev,fastapi,flask,django]
pytest
The FastAPI sample app lives under examples/fastapi_app.
Release Process
See RELEASING.md for version-bump instructions, changelog expectations, and details on how the GitHub Actions workflow publishes to PyPI.
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
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 google_authz_client-0.5.0.tar.gz.
File metadata
- Download URL: google_authz_client-0.5.0.tar.gz
- Upload date:
- Size: 15.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1ff415bc6b9d95f68beea0f9aea15495c08b63905819c0e5831a5b8110db568e
|
|
| MD5 |
8906dd0546a1a222c557199136f476ce
|
|
| BLAKE2b-256 |
f329b9f4da1ffbbed48c005725256262b06d47e7bee7565ba8ee0b15161a7028
|
File details
Details for the file google_authz_client-0.5.0-py3-none-any.whl.
File metadata
- Download URL: google_authz_client-0.5.0-py3-none-any.whl
- Upload date:
- Size: 15.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b567c0ef1d595676c4570621d9b5972459f1c0486fa86a541a56505845283ca
|
|
| MD5 |
c2b08ecb74b6181551caea9640e46c75
|
|
| BLAKE2b-256 |
99e3084779842f8f5a4552a0fa9c5e446dd02b3d17ded4c97b7a256519760df7
|