Skip to main content

Python SDK for authorizer.dev — self-hosted authentication & authorization

Project description

authorizer-python

Python SDK for authorizer.dev — self-hosted authentication & authorization.

Getting Started

You need a running Authorizer instance before using this SDK. See the deployment guide to spin one up.

Install

pip install authorizer-py

Initialize the client

Parameter Required Description
client_id Yes Your Authorizer app's client ID
authorizer_url Yes Base URL of your Authorizer instance (no trailing slash)
redirect_url No Default redirect URL used by magic-link and forgot-password flows
extra_headers No Additional headers sent on every request (e.g. custom Origin)
protocol No Transport: "graphql" (default), "rest", or "grpc"
grpc_endpoint No gRPC target host:port. The server's gRPC listener runs on a separate port (default 9091), not the HTTP URL's port. When unset, the host is derived from authorizer_url and port 9091 is used. Only used when protocol="grpc".

Sync:

from authorizer import AuthorizerClient

client = AuthorizerClient(
    client_id="YOUR_CLIENT_ID",
    authorizer_url="https://your-instance.authorizer.dev",
)
# use as a context manager to auto-close the HTTP session
with AuthorizerClient(
    client_id="YOUR_CLIENT_ID",
    authorizer_url="https://your-instance.authorizer.dev",
) as client:
    ...

Async:

from authorizer import AsyncAuthorizerClient

async with AsyncAuthorizerClient(
    client_id="YOUR_CLIENT_ID",
    authorizer_url="https://your-instance.authorizer.dev",
) as client:
    ...

Usage

Login

from authorizer import AuthorizerClient, LoginRequest

with AuthorizerClient(
    client_id="YOUR_CLIENT_ID",
    authorizer_url="https://your-instance.authorizer.dev",
) as client:
    token = client.login(LoginRequest(email="user@example.com", password="Abc@123"))
    if token.user:
        print("Logged in as:", token.user.email)
    print("access_token:", token.access_token)

Note (Authorizer >= v2.3.0): the server's CSRF guard requires an Origin header on state-changing requests. The client sends the Authorizer server's own origin by default, which always passes. If your instance restricts ALLOWED_ORIGINS, pass your app's origin instead via extra_headers: {"Origin": "https://your-app.com"}.

Fine-grained authorization (FGA)

Authorizer supports OpenFGA-style relationship-based access control. The subject of a permission check defaults to the authenticated caller — it is pinned server-side from the Authorization header you supply. The optional user field on CheckPermissionsRequest / ListPermissionsRequest is honored only for super-admins or when the value matches the caller's own identity.

from authorizer import (
    AuthorizerClient,
    CheckPermissionsRequest,
    ListPermissionsRequest,
    PermissionCheckInput,
)

client = AuthorizerClient("YOUR_CLIENT_ID", "https://your-instance.authorizer.dev")
auth = {"Authorization": "Bearer USER_ACCESS_TOKEN"}

# Check multiple relations in one call
checks = client.check_permissions(
    CheckPermissionsRequest(
        checks=[
            PermissionCheckInput(relation="can_view", object="document:1"),
            PermissionCheckInput(relation="can_edit", object="document:1"),
        ]
    ),
    headers=auth,
)
for r in checks.results:
    print(r.relation, r.object, r.allowed)

# List all objects the caller can view
accessible = client.list_permissions(
    ListPermissionsRequest(relation="can_view", object_type="document"),
    headers=auth,
)
print("can view:", accessible.objects)
client.close()

gRPC transport

Set protocol="grpc" to call the server over gRPC. This requires the optional gRPC dependencies:

pip install 'authorizer-py[grpc]'

The server's gRPC listener runs on a separate port (default 9091), not the HTTP URL's port (8080). When grpc_endpoint is unset, the host is taken from authorizer_url and port 9091 is used; pass grpc_endpoint to dial a custom target explicitly:

from authorizer import AuthorizerClient

client = AuthorizerClient(
    client_id="YOUR_CLIENT_ID",
    authorizer_url="https://your-instance.authorizer.dev",
    protocol="grpc",
    grpc_endpoint="your-instance.authorizer.dev:9091",  # optional; defaults to host:9091
)

License

Apache-2.0 — see LICENSE for details.

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

authorizer_py-0.2.0.tar.gz (80.6 kB view details)

Uploaded Source

Built Distribution

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

authorizer_py-0.2.0-py3-none-any.whl (84.6 kB view details)

Uploaded Python 3

File details

Details for the file authorizer_py-0.2.0.tar.gz.

File metadata

  • Download URL: authorizer_py-0.2.0.tar.gz
  • Upload date:
  • Size: 80.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for authorizer_py-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f101b88f4ecd7e45c16b248ebfbf20e78e592b96073c94505ce330a4eb1fa518
MD5 b1e4749cd22054811d77f90911f012d8
BLAKE2b-256 725eb8ea7191ed715c1842f4b81f850129ba8f174149bd5602dd2bb981d2ff56

See more details on using hashes here.

File details

Details for the file authorizer_py-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: authorizer_py-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 84.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for authorizer_py-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 21f296fd20948809b0e993d32adea6eb5f06de4baa8abaeb58cac6a732589222
MD5 0e56f9d353a61a4337222317d4c353a2
BLAKE2b-256 e74676d0b190e55bc00cf725ea9ec08402dc67562c021b7e868e15f986e763c0

See more details on using hashes here.

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