Quickstart¶
Install¶
pip install ogu-api
Python 3.11+. Pulls tls-client and beautifulsoup4 as runtime dependencies.
Login & a first request¶
import asyncio
from ogu_api import OGUClient
async def main() -> None:
async with OGUClient() as client:
await client.session.login('username', 'password')
user = await client.users.get_by_username('forgivenforget')
print(user.user_id, user.username, user.credits, user.reputation, user.vouches)
asyncio.run(main())
OGUClient is an async context manager. The underlying tls_client.Session is closed on __aexit__. Call client.close() if you manage the lifecycle yourself.
Two-factor auth¶
If 2FA is enabled, pass the current TOTP as the third positional arg:
await client.session.login('username', 'password', '123456')
Generate the TOTP yourself (e.g. with pyotp) — ogu-api does not store credentials or TOTP secrets.
Persisting the session¶
After login the cookies live on client.cookies. Save them to disk, secret manager, or Redis — whatever you want:
cookies = {cookie.name: cookie.value for cookie in client.cookies}
To resume on a fresh client:
client = OGUClient()
for name, value in cookies.items():
client.cookies.set(name, value)
Configuration¶
from ogu_api import OGUClient
client = OGUClient(
proxy = 'user:pass@host:8080',
timeout_seconds = 30.0,
max_retries = 3,
retry_backoff_seconds = 0.5,
client_identifier = 'chrome131',
)
Proxy strings are auto-normalized — user:pass@host:port, host:port:user:pass, or plain host:port all work.
For finer-grained control over the HTTP layer, pass an HttpClientConfig or your own preconfigured tls_client.Session.