Skip to main content

Profy App SDK — OAuth token management and event reporting

Project description

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 + SyncProfyApp (async) and ProfyAppSync (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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

profy_sdk-0.1.0.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

profy_sdk-0.1.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file profy_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: profy_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for profy_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 41f7c6b42c4199e474cbd6936cf557be2649a4fd9a593247cfec515b5255e9aa
MD5 63b1447099fdb9671bf978e1ced515b2
BLAKE2b-256 25c4550fc342d9f6a5349d57447ddaaab57128a8dd374f29f32f283570f9c2cb

See more details on using hashes here.

File details

Details for the file profy_sdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: profy_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for profy_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c2fea943182e161a208fc2c29e610e9398fa8cff9278b734408f31cb0b59888d
MD5 2a65edcb1df38ead62b68ca302ced17b
BLAKE2b-256 aa02ce34bcbaeb8405f84c8e8209fc11d989892c8403b8b5420e67ee6303f103

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page