DRP Python SDK
The official Python SDK for integrating the Digital Receipt Protocol into Python applications, including Django, Flask, FastAPI, and custom POS systems.Installation
- Python 3.8 or higher
- cryptography library (auto-installed)
Quick Start
Merchant Integration (Server-Side)
Django Integration
Flask Integration
FastAPI Integration
Configuration
Client Options
Environment Variables
API Reference
Client Methods
public_keys.get(card_token, transaction_id=None)
Retrieve customer’s public key for encryption.
dict with public key data
receipts.send(params)
Encrypt and send a receipt to the card issuer.
dict with receipt response
receipts.list(filters) - User Client Only
Retrieve user’s receipts.
dict with receipts list and pagination
merchants.register(data) - Class Method
Register merchant account (one-time setup).
dict with registration response
Async Support (FastAPI, asyncio)
All methods have async equivalents:Crypto Utilities
crypto.encrypt(data, public_key)
crypto.decrypt(encrypted_data, private_key)
crypto.sign(data, private_key)
crypto.verify(data, signature, public_key)
Error Handling
Exception Hierarchy
Testing
Mock Client
pytest Example
Webhooks
Handle webhook events from issuers:Best Practices
Use Environment Variables
Use Environment Variables
Never hardcode API keys. Use environment variables or secret management (AWS Secrets Manager, HashiCorp Vault).
Handle Exceptions Gracefully
Handle Exceptions Gracefully
Always catch
CustomerNotEnrolledError - not all customers have DRP enabled. This is normal and shouldn’t fail the checkout.Use Async in FastAPI
Use Async in FastAPI
FastAPI is async-native. Use
get_async() and send_async() methods for better performance.Cache Public Keys
Cache Public Keys
Public keys are valid for months. Cache them with Redis or in-memory cache to reduce API calls.
Log Errors, Don't Fail Checkout
Log Errors, Don't Fail Checkout
DRP errors shouldn’t prevent checkout. Log the error, fall back to email receipts, and investigate later.
Resources
GitHub Repository
Source code, examples, and issue tracking
PyPI Package
Package details and version history
API Reference
Complete API documentation
Support
Get help with integration
Changelog
v1.0.0 (Latest)
- Initial stable release
- Full support for DRP API v1
- Async/await support
- Django, Flask, FastAPI examples
- Type hints throughout
v0.9.0 (Beta)
- Beta release for testing
- Core merchant and user APIs