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),ssotwo_factor,organization(teams and dynamic roles included),admin,api_key,magic_link,email_otp,devicephone_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 (DCRregister, client CRUD,client.rotate_secret,authorize,token,introspect,revoke,userinfo,end_session, consent + consent CRUD;/oauth2/continueisoauth2.continue_—continueis a Python keyword)- root-mounted jwt-plugin routes as
token()/jwks(), plusis_username_available()anddelete_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
Release history Release notifications | RSS feed
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef70798741d839b331fcd4a795c3ba35ec34ec8e070b6a62ee9955c956bd97cd
|
|
| MD5 |
09e1ef8052d6bc44c4bb7bc00885e3c5
|
|
| BLAKE2b-256 |
e7625e4be22d44d22845160a91d252d0c5e1fac13171b379a5ef1eba57983c0f
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0273be53cb9018ccd1a2594d496f039755cd5684ce550f2927d1fb7e53464bd0
|
|
| MD5 |
d6a961c6f208ea8c9a48b83d4f5a04e7
|
|
| BLAKE2b-256 |
d67959371abc7a7f5c889fc93ee2b8aef21f39872792cf37f5f1dc98dd738788
|