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, oauth_popup, 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; /oauth2/continue is oauth2.continue_continue is a Python keyword)
  • 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).

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.2.0.tar.gz (8.8 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.2.0-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: better_auth_client-0.2.0.tar.gz
  • Upload date:
  • Size: 8.8 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.2.0.tar.gz
Algorithm Hash digest
SHA256 ef70798741d839b331fcd4a795c3ba35ec34ec8e070b6a62ee9955c956bd97cd
MD5 09e1ef8052d6bc44c4bb7bc00885e3c5
BLAKE2b-256 e7625e4be22d44d22845160a91d252d0c5e1fac13171b379a5ef1eba57983c0f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: better_auth_client-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 10.3 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0273be53cb9018ccd1a2594d496f039755cd5684ce550f2927d1fb7e53464bd0
MD5 d6a961c6f208ea8c9a48b83d4f5a04e7
BLAKE2b-256 d67959371abc7a7f5c889fc93ee2b8aef21f39872792cf37f5f1dc98dd738788

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