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.

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.1.0.tar.gz (6.9 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.1.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: better_auth_client-0.1.0.tar.gz
  • Upload date:
  • Size: 6.9 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.1.0.tar.gz
Algorithm Hash digest
SHA256 e23b6dfa6c1f4e92e89d159b7f1a90e4fa7122c491db24bc6604a6cbf1500713
MD5 0948e0d337588e57bca60b10dac93bc9
BLAKE2b-256 3b28254f3ab96572b91f2ca905e5faade95aa20180a88748fd703c057380874e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: better_auth_client-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ac1e60010c5ef7ff567f35910c986d59bf48317c0ce6b920d2d27745300e0348
MD5 77172efe7ef57d7b8257ed62a1c54135
BLAKE2b-256 4debfbe409cf4dc965283be013dc4494c14093577a947a3482cfb286a74f9959

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