Python SDK for GAuth API - GearVN Authentication Service
Project description
GAuth SDK for Python
Python SDK for GAuth API - GearVN Authentication Service.
Installation
pip install gauthsdk
Or install from source:
pip install -e .
Quick Start
from gauthsdk import Client
# Initialize client with API Key (for S2S operations)
client = Client(
api_key="gvn_sk_your_api_key_here",
base_url="http://localhost:3000",
)
# Get user by ID
user = client.users.get("user-uuid")
print(f"User: {user.full_name()}")
print(f"Email: {user.email}")
print(f"Role: {user.role}")
# List users with pagination
result = client.users.list(page=1, limit=20)
for user in result.users:
print(f"- {user.email}: {user.status}")
print(f"Total users: {result.paging.total}")
# Validate JWT token
claims = client.validate_token("user_jwt_token")
print(f"User ID: {claims.sub}")
print(f"Tenant ID: {claims.tenant_id}")
print(f"Role: {claims.role}")
Features
Users API
# Get user by ID
user = client.users.get("user-uuid")
# List users with filters
result = client.users.list(
page=1,
limit=20,
status="active",
role="user",
search="john",
)
# List user sessions
sessions = client.users.list_sessions("user-uuid")
for session in sessions:
print(f"Session: {session.id}, Created: {session.created_at}")
# Revoke a session
client.users.revoke_session("user-uuid", "session-uuid")
Auth API
For auth operations (login, register, etc.), you need to set tenant_id:
client = Client(
api_key="gvn_sk_...",
tenant_id="tenant-uuid",
base_url="http://localhost:3000",
)
# Login
tokens = client.auth.login("user@example.com", "password")
print(f"Access Token: {tokens.access_token}")
print(f"Refresh Token: {tokens.refresh_token}")
# Refresh token
new_tokens = client.auth.refresh_token(tokens.refresh_token)
print(f"New Access Token: {new_tokens.access_token}")
# Validate token
claims = client.auth.validate_token(tokens.access_token)
print(f"User: {claims.sub}")
Error Handling
from gauthsdk import Client, APIError
client = Client(api_key="gvn_sk_...")
try:
user = client.users.get("invalid-uuid")
except APIError as e:
print(f"Error {e.code}: {e.message}")
if e.is_not_found():
print("User not found")
elif e.is_unauthorized():
print("Invalid API key")
elif e.is_forbidden():
print("Insufficient permissions")
elif e.is_rate_limited():
print("Too many requests, please slow down")
Configuration
| Parameter | Description | Default |
|---|---|---|
api_key |
API Key for authentication (X-API-Key header) |
None |
base_url |
Base URL for the API | http://localhost:3000 |
tenant_id |
Tenant ID for multi-tenant operations | None |
timeout |
Request timeout in seconds | 30 |
Requirements
- Python 3.8+
requestslibrary
License
MIT
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
gauthsdk-0.2.0.tar.gz
(8.7 kB
view details)
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 gauthsdk-0.2.0.tar.gz.
File metadata
- Download URL: gauthsdk-0.2.0.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5932a5c06f09687d97e3d9158a238699ca67545848f659bb417491942535cbd9
|
|
| MD5 |
8dd944d9437a39ad09d2debea2cc484f
|
|
| BLAKE2b-256 |
32b84c836e9f6c18bc3363f850514a716aa48e0ce053bc009d003b576a501661
|
File details
Details for the file gauthsdk-0.2.0-py3-none-any.whl.
File metadata
- Download URL: gauthsdk-0.2.0-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d5640c146443953444227c16670d1e591509beea4db8faece324e6a980b1b454
|
|
| MD5 |
0f55e2519bfda54267483720a2026697
|
|
| BLAKE2b-256 |
125250d37215ce60cc2a61906d62eda756053ca92b167298be5ef9cd04497815
|