Python SDK for CredGem API - A powerful credit management system
Project description
CredGem Python SDK
A Python SDK for interacting with the CredGem API. Manage digital credits, wallets, and transactions with a simple, intuitive interface.
Features
- 🏦 Wallet management
- 💳 Transaction operations (deposits, holds, debits)
- 🏷️ Credit type operations
- 📊 Insights and analytics
- ⚡ Async support with context managers
- 🔍 Type hints for better IDE integration
- 🔄 Automatic hold release on errors
- 🎯 Idempotent operations
- ⚙️ Environment-specific configurations
Installation
pip install credgem-sdk
Quick Start
from credgem import CredGemClient
from decimal import Decimal
async with CredGemClient(api_key="your-api-key") as client:
# Create a wallet
wallet = await client.wallets.create(
name="Customer Wallet",
context={"customer_id": "cust_123"}
)
# Deposit credits
await client.transactions.deposit(
wallet_id=wallet.id,
amount=100.00,
credit_type_id="POINTS",
description="Welcome bonus"
)
# Check balance
balance = await client.wallets.get_balance(wallet.id)
print(f"Wallet balance: {balance.available_amount} {balance.credit_type_id}")
Configuration
Configure the SDK for different environments:
from credgem import CredGemClient
# Production
client = CredGemClient(
api_key="your-api-key",
base_url="https://api.credgem.com" # Default
)
# Staging
client = CredGemClient(
api_key="your-staging-key",
base_url="https://api.staging.credgem.com"
)
# Local development
client = CredGemClient(
api_key="your-dev-key",
base_url="http://localhost:8000"
)
Transaction Operations
Deposits
await client.transactions.deposit(
wallet_id=wallet.id,
amount=100.00,
credit_type_id="POINTS",
description="Welcome bonus",
issuer="system",
external_id="welcome_bonus_123", # For idempotency
context={"source": "welcome_bonus"}
)
Holds and Debits
Use the draw_credits context manager for safe credit operations:
# Hold and debit pattern
async with client.draw_credits(
wallet_id=wallet.id,
credit_type_id="POINTS",
amount=50.00,
description="Purchase with hold",
issuer="store_app",
context={"order_id": "order_123"}
) as draw:
# Process your order here
order_success = await process_order()
if order_success:
await draw.debit() # Completes the transaction
# Hold is automatically released if no debit is called
Direct Debits
For immediate debits without holds:
async with client.draw_credits(
wallet_id=wallet.id,
credit_type_id="POINTS",
description="Direct purchase",
issuer="store_app",
skip_hold=True
) as draw:
await draw.debit(amount=25.00)
Manual Hold Operations
For more control over the hold process:
# Create a hold
hold = await client.transactions.hold(
wallet_id=wallet.id,
amount=25.00,
credit_type_id="POINTS",
description="Hold for pending purchase"
)
# Release a hold
await client.transactions.release(
wallet_id=wallet.id,
hold_transaction_id=hold.id,
description="Release pending hold"
)
# Debit against a hold
await client.transactions.debit(
wallet_id=wallet.id,
amount=25.00,
credit_type_id="POINTS",
description="Purchase completion",
hold_transaction_id=hold.id
)
Wallet Operations
# Create a wallet
wallet = await client.wallets.create(
name="My Wallet",
context={"customer_id": "cust_123"}
)
# Get wallet details
wallet = await client.wallets.get(wallet.id)
# List transactions
transactions = await client.transactions.list(
wallet_id=wallet.id,
limit=10,
offset=0
)
# Get wallet balance
balance = await client.wallets.get_balance(
wallet_id=wallet.id,
credit_type_id="POINTS"
)
Error Handling
The SDK provides clear error messages and proper exception handling:
from credgem.exceptions import InsufficientCreditsError, WalletNotFoundError
try:
async with client.draw_credits(...) as draw:
await draw.debit(amount=1000.00)
except InsufficientCreditsError:
print("Not enough credits available")
except InvalidRequestError:
print("Invalid request")
Documentation
For detailed documentation, API reference, and more examples, visit:
Support
- 📧 Email: support@credgem.com
- 💬 Discord: Join our community
- 🐛 Issues: GitHub Issues
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
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 credgem_sdk-0.1.7.tar.gz.
File metadata
- Download URL: credgem_sdk-0.1.7.tar.gz
- Upload date:
- Size: 10.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.0 CPython/3.10.1 Darwin/24.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
27d99b8b4b3b25ea556112efb2a9dbc272ac88e9ba73bb8c1d4e4192603f9d36
|
|
| MD5 |
9291e78abca4145559d5330aefad1892
|
|
| BLAKE2b-256 |
9cc160b3f9fd9391c1dd25993673be38ede46b2177787503e37a375e83520df6
|
File details
Details for the file credgem_sdk-0.1.7-py3-none-any.whl.
File metadata
- Download URL: credgem_sdk-0.1.7-py3-none-any.whl
- Upload date:
- Size: 13.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.0 CPython/3.10.1 Darwin/24.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
60ac767ea05eb18e725c226b316a77e003afc932175e5c3ad1f454448c505af8
|
|
| MD5 |
cf27bcce1233b73f1eccc00057ab7499
|
|
| BLAKE2b-256 |
de98dacf89b3c3cd1f14a5dbbd8308a4751a77561d61a28abcb014a841e5b774
|