Codex OAuth-based Python SDK with resource-style Client and AsyncClient APIs
Project description
oauth-codex
OAuth PKCE-based Python SDK for the Codex backend.
Highlights
- Resource-style clients:
ClientandAsyncClient - OAuth PKCE only, with interactive login and automatic token refresh
- OpenAI-style
chat.completions.create(...) - Lower-level
responses.create(...),responses.parse(...), andresponses.stream(...) - Callable tool loop helpers via
client.beta.chat.completions.run_tools(...)
Installation
pip install oauth-codex
Requires Python 3.11 or newer.
Quick Start
Synchronous Client
from oauth_codex import Client
client = Client()
client.authenticate()
completion = client.chat.completions.create(
model="gpt-5.3-codex",
messages=[{"role": "user", "content": "Hello from oauth-codex"}],
)
print(completion.choices[0].message.content)
Asynchronous Client
import asyncio
from oauth_codex import AsyncClient
async def main():
client = AsyncClient()
await client.authenticate()
completion = await client.chat.completions.create(
model="gpt-5.3-codex",
messages=[{"role": "user", "content": "Hello async"}],
)
print(completion.choices[0].message.content)
asyncio.run(main())
Authentication
This SDK uses OAuth PKCE only. API keys are not supported.
client = Client()
client.authenticate()
On first authentication, the SDK prints an authorization URL, waits for the browser sign-in flow, and asks you to paste the localhost callback URL back into the terminal. Tokens are stored locally and refreshed automatically on later requests.
Main API Surface
Chat Completions
response = client.chat.completions.create(
model="gpt-5.3-codex",
messages=[{"role": "user", "content": "Write a sorting function"}],
)
print(response.choices[0].message.content)
Responses Resource
response = client.responses.create(
model="gpt-5.3-codex",
input=[{"role": "user", "content": "Analyze this code snippet."}],
)
print(response.output_text)
Streaming
for event in client.responses.stream(
model="gpt-5.3-codex",
input=[{"role": "user", "content": "Say hello in three words"}],
):
if event.type == "text_delta" and event.delta:
print(event.delta, end="", flush=True)
Structured Output
from pydantic import BaseModel
class Summary(BaseModel):
title: str
score: int
response = client.responses.parse(
model="gpt-5.3-codex",
input=[{"role": "user", "content": "Return JSON with title and score"}],
response_format=Summary,
)
print(response.parsed)
Tool Execution
def add(a: int, b: int) -> int:
return a + b
completion = client.beta.chat.completions.run_tools(
model="gpt-5.3-codex",
messages=[{"role": "user", "content": "What is 2 + 3?"}],
tools=[add],
)
print(completion.choices[0].message.content)
Available Namespaces
client.chat.completionsclient.responsesclient.filesclient.vector_storesclient.vector_stores.filesclient.vector_stores.file_batchesclient.modelsclient.beta.chat.completions
AsyncClient exposes the same namespaces with async methods.
Removed In 4.0
authenticate_on_initgenerate,agenerate,stream,astream- legacy
OAuthCodexClientandAsyncOAuthCodexClient - module-level proxy usage such as
oauth_codex.responses.create(...)
Error Handling
The package exports OpenAI-style exception classes such as AuthenticationError, RateLimitError, APIConnectionError, and APIStatusError.
Documentation
- English:
docs/en/index.md - Korean:
docs/ko/index.md
Development
pip install -e .[dev]
pytest -q
python -m build
Changelog
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 oauth_codex-4.0.0.tar.gz.
File metadata
- Download URL: oauth_codex-4.0.0.tar.gz
- Upload date:
- Size: 35.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8288a08bdfc05174e32fad76a6c0f832ea5df178b8907bea5c861a8116213972
|
|
| MD5 |
bcc477c58920bbe53af86093cb5d4784
|
|
| BLAKE2b-256 |
609bdab1d6f4d1a9554e4ac094de489e15a8bc24284deaa184bd2963db8998ec
|
Provenance
The following attestation bundles were made for oauth_codex-4.0.0.tar.gz:
Publisher:
publish-pypi.yml on smturtle2/oauth-codex
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
oauth_codex-4.0.0.tar.gz -
Subject digest:
8288a08bdfc05174e32fad76a6c0f832ea5df178b8907bea5c861a8116213972 - Sigstore transparency entry: 1073567321
- Sigstore integration time:
-
Permalink:
smturtle2/oauth-codex@6d6895636e143e561cadafb7133e8675ac3774aa -
Branch / Tag:
refs/tags/v4.0.0 - Owner: https://github.com/smturtle2
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@6d6895636e143e561cadafb7133e8675ac3774aa -
Trigger Event:
push
-
Statement type:
File details
Details for the file oauth_codex-4.0.0-py3-none-any.whl.
File metadata
- Download URL: oauth_codex-4.0.0-py3-none-any.whl
- Upload date:
- Size: 45.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ccf872d8929b23b624c4dc75aa9718f927e31e86438107bc4217f4d4986913c6
|
|
| MD5 |
26393f3f4c788713458c87f523bd9800
|
|
| BLAKE2b-256 |
f5d341a42a8d90b850d55bfe8b75ea58b56cd46250659a55f6b72b9d7530ec0c
|
Provenance
The following attestation bundles were made for oauth_codex-4.0.0-py3-none-any.whl:
Publisher:
publish-pypi.yml on smturtle2/oauth-codex
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
oauth_codex-4.0.0-py3-none-any.whl -
Subject digest:
ccf872d8929b23b624c4dc75aa9718f927e31e86438107bc4217f4d4986913c6 - Sigstore transparency entry: 1073567397
- Sigstore integration time:
-
Permalink:
smturtle2/oauth-codex@6d6895636e143e561cadafb7133e8675ac3774aa -
Branch / Tag:
refs/tags/v4.0.0 - Owner: https://github.com/smturtle2
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@6d6895636e143e561cadafb7133e8675ac3774aa -
Trigger Event:
push
-
Statement type: