profy-sdk
Official Python SDK for the Profy App platform — OAuth token management and event reporting.
Installation
pip install profy-sdk
# With optional SQLAlchemy token storage:
pip install profy-sdk[sqlalchemy]
Quick Start
from profy import ProfyApp
async with ProfyApp(
client_id="your-app-id",
client_secret="your-app-secret",
) as profy:
# Exchange authorization code for tokens
token = await profy.exchange_code(code, "https://your-app.com/callback")
# Report a billing event
await profy.report_event("generate_report", token=token)
Synchronous Usage
from profy import ProfyAppSync
with ProfyAppSync(
client_id="your-app-id",
client_secret="your-app-secret",
) as profy:
token = profy.exchange_code(code, redirect_uri)
profy.report_event("generate_report", token=token)
Features
- OAuth2 Authorization Code Flow — exchange codes, refresh tokens automatically
- Events API — report billing events with auto token refresh and retry on 401
- Async + Sync —
ProfyApp(async) andProfyAppSync(sync) clients - Type hints — full type annotations, PEP 561 compatible
- Minimal dependencies — only
httpx - Optional SQLAlchemy integration — pre-built token model + store
Token Persistence (Optional)
Using SQLAlchemy
from profy import ProfyApp
from profy.contrib.sqlalchemy import create_token_model, SQLAlchemyTokenStore
# 1. Create the ORM model (auto-creates table with Base.metadata.create_all())
ProfyOAuthToken = create_token_model(Base)
# 2. Create store
store = SQLAlchemyTokenStore(async_session_factory, ProfyOAuthToken)
# 3. Initialize SDK with persistence
profy = ProfyApp(
client_id="...",
client_secret="...",
on_token_refresh=store.on_refresh,
)
# 4. Save after exchange
token = await profy.exchange_code(code, redirect_uri)
await store.save(token.user_id, token, scope="events:write")
# 5. Load later
saved = await store.load(user_id)
Custom Storage
from profy import ProfyApp, TokenData
async def persist_token(token: TokenData):
await redis.set(f"profy:{token.user_id}", token.access_token)
profy = ProfyApp(
client_id="...",
client_secret="...",
on_token_refresh=persist_token,
)
API Reference
ProfyApp / ProfyAppSync
| Method | Description |
|---|---|
exchange_code(code, redirect_uri) |
Exchange authorization code for tokens |
refresh_token(refresh_token) |
Manually refresh an expired token |
report_event(event_name, *, token, idempotency_key?, metadata?) |
Report a billing event |
TokenData
@dataclass
class TokenData:
access_token: str
refresh_token: str
user_id: str
expires_at: float # unix timestamp
@property
def is_expired(self) -> bool: ...
Exceptions
| Class | Status | Description |
|---|---|---|
AuthExpired |
401 | Token expired and refresh failed |
InsufficientBalance |
402 | User has insufficient credits |
InvalidEvent |
400 | Event name not configured |
ProfyApiError |
varies | Generic API error |
Documentation
License
MIT
Metadata
Release files for profy-sdk 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| profy_sdk-0.1.0.tar.gz | 7.7 kB | Without provenance | Details for profy_sdk-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| profy_sdk-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for profy_sdk-0.1.0-py3-none-any.whl |
Total release size: 15.5 kB
Release files / profy_sdk-0.1.0.tar.gz
| Download URL | profy_sdk-0.1.0.tar.gz |
|---|---|
| Size | 7.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
41f7c6b42c4199e474cbd6936cf557be2649a4fd9a593247cfec515b5255e9aa
|
|
BLAKE2b-256 checksum How to use checksums |
25c4550fc342d9f6a5349d57447ddaaab57128a8dd374f29f32f283570f9c2cb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|
Release files / profy_sdk-0.1.0-py3-none-any.whl
| Download URL | profy_sdk-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c2fea943182e161a208fc2c29e610e9398fa8cff9278b734408f31cb0b59888d
|
|
BLAKE2b-256 checksum How to use checksums |
aa02ce34bcbaeb8405f84c8e8209fc11d989892c8403b8b5420e67ee6303f103
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|
Security for profy-sdk 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.