Memberful service Python client for webhooks and API
Project description
Memberful Python SDK
A modern, type-safe Python SDK for integrating with Memberful's API and webhooks. Built with Pydantic models for comprehensive type hints and runtime validation.
✨ Key Features
- 🔒 Type Safety: Full Pydantic model coverage for all API responses and webhook events
- 🚀 Async First: Built on
httpxfor high-performance async operations - ⚡ GraphQL Powered: Efficient data fetching with Memberful's GraphQL API
- 🔄 Resilient: Smart retry logic with exponential backoff handles network hiccups and rate limits automatically
- 📝 Auto-Complete Heaven: Comprehensive type hints mean your IDE knows exactly what's available
- 🎯 Zero Guesswork: No more digging through API docs to figure out response formats
- 🪝 Webhook Support: Parse and validate webhook events with confidence
- 📚 Rich Documentation: Detailed examples and comprehensive API documentation
- 🧪 Battle-Tested: Extensive test suite ensures reliability
- 🐍 Modern Python: Supports Python 3.10+ with all the latest features
📦 Installation
uv pip install memberful
Or with uv project management:
uv add memberful
🚀 Quick Start
API Client
from memberful.api import MemberfulClient
# Initialize the client
async with MemberfulClient(api_key="YOUR_API_KEY") as client:
# Get all members with full type safety
members = await client.get_all_members()
for member in members:
print(f"{member.full_name} - {member.email}")
# Your IDE provides auto-complete for all attributes!
if member.subscriptions:
active_subs = [s for s in member.subscriptions if s.active]
print(f" Active subscriptions: {len(active_subs)}")
Webhook Handling
from memberful.webhooks import (
parse_payload,
validate_signature,
MemberSignupEvent,
SubscriptionCreatedEvent
)
import json
def handle_webhook(request_body: str, signature_header: str, webhook_secret: str):
# Verify the webhook signature
if not validate_signature(
payload=request_body,
signature=signature_header,
secret_key=webhook_secret
):
raise ValueError("Invalid webhook signature")
# Parse the event with full type safety
event = parse_payload(json.loads(request_body))
# Handle different event types with isinstance checks
match event:
case MemberSignupEvent():
print(f"New member: {event.member.email}")
case SubscriptionCreatedEvent():
print(f"New subscription for: {event.member.email}")
case _:
print(f"Received {event.event} event")
📖 Documentation
Comprehensive Guides
- API Documentation - Complete guide to using the API client with examples
- Webhook Documentation - Detailed webhook event reference and handling guide
Quick Examples
Check out the examples directory for ready-to-run code:
- Basic API Usage - Simple examples to get started
- Webhook Usage - Webhook handling patterns
- Webhook Parsing - Detailed webhook parsing examples
- FastAPI Integration - Complete FastAPI webhook server
🛠️ Core Features
API Client Capabilities
- ✅ Fetch members (individual, paginated, or all)
- ✅ Retrieve subscriptions with full plan details
- ✅ Automatic pagination handling
- ✅ Smart retry logic with exponential backoff (3 attempts, handles network errors)
- ✅ Configurable timeouts and retries
- ✅ Type-safe responses with Pydantic models
- ✅ Comprehensive error handling
Webhook Features
- ✅ Type-safe parsing of all webhook event types
- ✅ Automatic signature verification
- ✅ Support for all 16 Memberful webhook events:
- Member events: signup, updated, deleted
- Subscription events: created, updated, activated, deleted, renewed
- Order events: completed, suspended
- Plan events: created, updated, deleted
- Download events: created, updated, deleted
- ✅ Pydantic models for each event type
- ✅ Helper functions for event handling
🏗️ Architecture
This SDK is built with modern Python best practices:
- GraphQL API - leverages Memberful's GraphQL endpoint for efficient data fetching
- Async/await for efficient I/O operations
- Pydantic v2 for fast data validation and serialization
- Type hints throughout for better IDE support
- Minimal dependencies - just
httpx,pydantic, andstaminafor resilient retries - 100% test coverage for reliability
🧪 Testing
The SDK includes a comprehensive test suite. Run tests with:
# Install dev dependencies
uv pip install -e ".[dev]"
# Run tests
pytest
# Run with coverage
pytest --cov=memberful
🤝 Contributing
We love contributions! If you've found a bug or have a feature request:
- Check existing issues first to avoid duplicates
- Open an issue to discuss the change
- Submit a PR with your improvements
Development Setup
# Clone the repo
git clone https://github.com/mikeckennedy/memberful.git
cd memberful
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install in development mode
uv pip install -e ".[dev]"
# Run tests
pytest
# Format code
ruff format
# Run linter
ruff check
📊 Project Status
This SDK is under active development and currently supports:
- ✅ Member operations (read)
- ✅ Subscription operations (read)
- ✅ All webhook event types
- ✅ Signature verification
- ⏳ Member operations (create/update) - coming soon
- ✅ GraphQL API integration with automatic retries
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
- Built with ❤️ for the Memberful community
- Inspired by modern Python SDK design patterns
- Special thanks to all contributors
📬 Support
Ready to integrate Memberful into your Python application? Get started now!
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
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 memberful-0.2.0.tar.gz.
File metadata
- Download URL: memberful-0.2.0.tar.gz
- Upload date:
- Size: 15.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b2bbb3b09f31c683afbd6f731a2541fd11977e7eefc536aa7c8058141a42a827
|
|
| MD5 |
7bd1e41603850738c8403b34487f72d9
|
|
| BLAKE2b-256 |
7367aa28f07de46739e5b8f887d0e65838c863b859501d6418ff7b47aefd924f
|
File details
Details for the file memberful-0.2.0-py3-none-any.whl.
File metadata
- Download URL: memberful-0.2.0-py3-none-any.whl
- Upload date:
- Size: 17.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f599d0c63393b15dd56e6201328d9c5ec71880705b19e93ec2957da60f586fe7
|
|
| MD5 |
11c8e63b0dbcd2d322741b7b52b80ab8
|
|
| BLAKE2b-256 |
2015834c83ed9cb7d28d2152e71a6967cfbdfe880ed87cf2c45d8c7a8c5527a2
|