Fastpy Libs
Clean facades for common tasks. Simple, fluent APIs for HTTP requests, email, caching, storage, queues, events, notifications, hashing, and encryption.
Why Facades?
Facades provide a simple, testable interface to complex underlying services. Import once, use everywhere with a consistent API.
Installation
Libs are included with fastpy-cli:
bash
pip install fastpy-cliQuick Start
python
from fastpy_cli.libs import Http, Mail, Cache, Storage, Queue, Event, Notify, Hash, CryptAvailable Facades
Http
HTTP client with fluent API
SMTP, SendGrid, Mailgun, SES
Cache
Memory, File, Redis
Storage
Local, S3, Memory
Queue
Sync, Redis, Database
Event
Event dispatcher with wildcards
Notify
Mail, Database, Slack, SMS
Hash
bcrypt, argon2, sha256
Crypt
Fernet, AES-256-CBC
Quick Examples
HTTP Requests
python
from fastpy_cli.libs import Http
# GET request with bearer token
response = Http.with_token('api-key').get('https://api.example.com/users')
if response.ok:
users = response.json()
# POST with JSON body
response = Http.post('https://api.example.com/users', json={'name': 'John'})Caching
python
from fastpy_cli.libs import Cache
# Store value with TTL
Cache.put('users', users_list, ttl=3600)
# Remember pattern (get or compute)
users = Cache.remember('users', 3600, lambda: fetch_users_from_db())
# Check and get
if Cache.has('config'):
config = Cache.get('config')Email
python
from fastpy_cli.libs import Mail
Mail.to('user@example.com') \
.subject('Welcome!') \
.send('welcome', {'name': 'John'})File Storage
python
from fastpy_cli.libs import Storage
# Store file
Storage.put('avatars/user.jpg', image_bytes)
# Get URL
url = Storage.url('avatars/user.jpg')
# Use S3
Storage.disk('s3').put('backups/data.zip', content)Job Queues
python
from fastpy_cli.libs import Queue, Job
class SendEmailJob(Job):
def __init__(self, user_id: int):
self.user_id = user_id
def handle(self):
user = get_user(self.user_id)
send_email(user.email)
# Push to queue
Queue.push(SendEmailJob(user_id=1))
# Delay execution
Queue.later(60, SendEmailJob(user_id=1))Events
python
from fastpy_cli.libs import Event
# Register listener
@Event.listen('user.registered')
def send_welcome(data):
Mail.to(data['email']).send('welcome')
# Dispatch event
Event.dispatch('user.registered', {'email': 'user@example.com'})Password Hashing
python
from fastpy_cli.libs import Hash
# Hash password
hashed = Hash.make('password')
# Verify
if Hash.check('password', hashed):
print('Valid!')Encryption
python
from fastpy_cli.libs import Crypt
# Encrypt (auto JSON serializes complex types)
encrypted = Crypt.encrypt({'user_id': 123, 'token': 'abc'})
# Decrypt
data = Crypt.decrypt(encrypted)CLI Command
View all available libs:
bash
# List all facades
fastpy libs
# Show usage examples for a specific facade
fastpy libs http --usage
fastpy libs cache --usageTesting Support
All facades provide .fake() methods for testing:
python
from fastpy_cli.libs import Http
# Fake HTTP responses
Http.fake({'https://api.example.com/*': {'status': 200, 'json': {'ok': True}}})
response = Http.get('https://api.example.com/test')
Http.assert_sent('https://api.example.com/test')python
from fastpy_cli.libs import Mail
# Fake mail
Mail.fake()
Mail.to('user@example.com').send('welcome')
Mail.assert_sent('welcome')
Mail.assert_sent_to('user@example.com')python
from fastpy_cli.libs import Cache
# Fake cache
Cache.fake()
Cache.put('key', 'value')
Cache.assert_has('key')
Cache.assert_missing('other_key')