Skip to main content

Python HTTP client for better-auth servers (better-auth-server or the TypeScript original).

Project description

better-auth-client

Python HTTP client for better-auth servers — the TypeScript original or better-auth-server (same wire).

pip install better-auth-client

Quickstart

Sync (httpx.Client):

from better_auth_client import AuthClient

client = AuthClient("http://localhost:8000")  # base_path defaults to /api/auth

client.sign_up.email(name="Ada", email="ada@example.com", password="s3cret-password")
client.sign_in.email(email="ada@example.com", password="s3cret-password")
session = client.get_session()          # dict, or None when unauthenticated
client.sign_out()

Async (httpx.AsyncClient) — same surface, awaited:

from better_auth_client import AsyncAuthClient

client = AsyncAuthClient("http://localhost:8000")
await client.sign_in.email(email="ada@example.com", password="s3cret-password")
session = await client.get_session()

Kwargs are sent verbatim as wire keys (JSON body on POST, query params on GET), so camelCase wire fields stay camelCase: client.forget_password(email=..., redirectTo=...).

Errors raise APIError(status, code, message, body) with the exact wire code. Redirect responses (e.g. the OAuth authorization step) are returned as-is, never followed.

Service-to-service

Validate a forwarded session token (server bearer plugin) without cookies:

client = AuthClient("http://auth.internal")
client.set_bearer(forwarded_token)      # from the set-auth-token response header
session = client.get_session()          # None if the token is invalid/expired

When the server has the bearer plugin enabled, the client also captures set-auth-token automatically after sign-in.

Device flow (RFC 8628)

For CLIs and other input-constrained clients (server device-authorization plugin):

flow = client.device.flow("my-cli")
print(f"Visit {flow.verification_uri} and enter {flow.user_code}")
token = flow.poll()                     # blocks (awaits, for AsyncAuthClient)
client.set_bearer(token["access_token"])

poll() honors the server's interval, backs off on slow_down, keeps waiting on authorization_pending, and raises APIError on denial or expiry.

Coverage

161 endpoints, mirroring the server routes: the full core surface plus

  • sign_in.*email, social, username, phone_number, anonymous, magic_link, email_otp, oauth2 (generic-oauth), sso
  • two_factor, organization (teams and dynamic roles included), admin, api_key, magic_link, email_otp, device
  • phone_number, passkey, siwe, one_tap, one_time_token, multi_session, sso (domain verification included)
  • oauth2 — generic-oauth (link) plus the whole oauth-provider surface (DCR register, client CRUD, client.rotate_secret, authorize, token, introspect, revoke, userinfo, end_session, consent + consent CRUD)
  • root-mounted jwt-plugin routes as token() / jwks(), plus is_username_available() and delete_anonymous_user()

Server plugins without mounted routes need no client namespace: bearer (automatic set-auth-token capture, above), captcha, have-i-been-pwned, last-login-method, custom-session (shadows get_session), oauth-proxy (browser-redirect callback only), oauth-popup (popup navigation only).

The rule for what is included: an entry exists when the request is genuinely emitted by a Python program — headless or relaying for a browser (BFF, server-rendered pages, CLIs). Routes only the end user's own browser ever requests (/oauth2/continue, /oauth-popup/start, redirect callbacks) are deliberately not part of the client.

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

better_auth_client-0.3.0.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

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

better_auth_client-0.3.0-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file better_auth_client-0.3.0.tar.gz.

File metadata

  • Download URL: better_auth_client-0.3.0.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for better_auth_client-0.3.0.tar.gz
Algorithm Hash digest
SHA256 1a9c669764f734f9ade8789a88833a036ce3e9aa7c5d19b098d8c8c2bac764f0
MD5 ae0d5e523bbb742877f1f5734bbcfb80
BLAKE2b-256 a23454a888825c36f78ee6d45ddd8377695d13f5eba4ddd6027073ec7ec6c4bd

See more details on using hashes here.

File details

Details for the file better_auth_client-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: better_auth_client-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for better_auth_client-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 92fb07838c89879b8cc088bf03fe50245fe9a809a9a555a0796f2fa420011ab1
MD5 5f895c340fe33f8327ea13fb8f658b75
BLAKE2b-256 8dffa70696e0466d5f9a379346b03f5d435e65fbca678d726599e5a7b9bcaf7a

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