HelloJohn / docs
SDKsPython SDK

Sessions

Manage user sessions with the HelloJohn Python SDK — list, revoke, and verify sessions from your backend.

Sessions

The Python SDK provides a sessions service for managing user sessions.

from hellojohn import HelloJohn

hj = HelloJohn(
    tenant_id=os.environ["HELLOJOHN_TENANT_ID"],
    secret_key=os.environ["HELLOJOHN_SECRET_KEY"],
)

List Sessions

result = hj.sessions.list("usr_01HABCDEF123456")

for session in result.sessions:
    print(f"{session.id} — IP: {session.ip_address}, active: {not session.revoked}")

Revoke a Session

hj.sessions.revoke("ses_01HABCDEF123456")

Revoke All Sessions

Force sign-out all devices:

hj.sessions.revoke_all("usr_01HABCDEF123456")

Verify a Session

Real-time check against HelloJohn's session store:

result = hj.sessions.verify("ses_01HABCDEF123456")
if not result.valid:
    raise HTTPException(status_code=401, detail="Session revoked")

Async

from hellojohn.asyncio import AsyncHelloJohn

hj = AsyncHelloJohn(...)

async def revoke_all(user_id: str):
    await hj.sessions.revoke_all(user_id)

On this page