Core utilities and models for FireFeed microservices
Project description
FireFeed Core
Core utilities and models for FireFeed microservices architecture.
FireFeed Core is a shared library that provides common components for all FireFeed microservices, ensuring consistency, security, and reliability across the distributed system.
๐ Features
- API Client: Robust HTTP client with authentication, retry policies, circuit breaker, and rate limiting
- JWT Authentication: Service-to-service authentication with token management
- Exception Handling: Comprehensive exception hierarchy for consistent error handling
- Configuration: Pydantic-based configuration management
- Interfaces: Abstract interfaces for service contracts
- Utilities: Common utility functions and helpers
๐ฆ Installation
pip install firefeed-core
๐ง Quick Start
Basic API Client Usage
import asyncio
from firefeed_core import APIClient
async def main():
# Initialize API client
async with APIClient(
base_url="http://firefeed-api:8000",
token="your-jwt-token",
service_id="firefeed-rss-parser"
) as client:
# Make authenticated requests
feeds = await client.get("/api/v1/internal/rss/feeds")
print(f"Found {len(feeds)} feeds")
# Create new RSS item
new_item = await client.post("/api/v1/internal/rss/items", {
"title": "Test Article",
"content": "This is a test article",
"feed_id": 123
})
asyncio.run(main())
JWT Token Management
from firefeed_core import ServiceTokenManager
# Generate token for service
token_manager = ServiceTokenManager(
secret_key="your-secret-key",
issuer="firefeed-api"
)
token = token_manager.generate_service_token(
service_id="firefeed-rss-parser",
audience="firefeed-api",
scopes=["rss:read", "rss:write"]
)
# Verify token
payload = token_manager.verify_token(token)
print(f"Token for service: {payload.sub}")
Exception Handling
from firefeed_core import APIException, NotFoundException
try:
result = await client.get("/api/v1/internal/rss/feeds/999")
except NotFoundException as e:
print(f"Feed not found: {e.message}")
except APIException as e:
print(f"API error: {e.message}")
๐ Authentication
FireFeed Core uses JWT tokens for service-to-service authentication. Each service needs:
- Service Token: JWT token with appropriate scopes
- Service ID: Unique identifier for the service
- Secret Key: Shared secret for token verification
Environment Configuration
Each service should have its own .env file:
# firefeed-rss-parser/.env
FIREFEED_API_URL=http://firefeed-api:8000
FIREFEED_API_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
FIREFEED_RSS_PARSER_SERVICE_ID=rss-parser
# firefeed-telegram-bot/.env
FIREFEED_API_URL=http://firefeed-api:8000
FIREFEED_API_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
FIREFEED_TELEGRAM_BOT_SERVICE_ID=telegram-bot
Token Scopes
Services can be granted specific scopes for different operations:
rss:read- Read RSS datarss:write- Create/modify RSS datausers:read- Read user datausers:write- Modify user datacategories:read- Read categoriescategories:write- Modify categories
๐ ๏ธ Advanced Features
Circuit Breaker
Automatically prevents requests to failing services:
from firefeed_core import APIClient
client = APIClient(
base_url="http://service:8000",
token="token",
service_id="my-service",
circuit_breaker_failure_threshold=5,
circuit_breaker_timeout=60
)
Retry Policies
Configurable retry with exponential backoff:
client = APIClient(
base_url="http://service:8000",
token="token",
service_id="my-service",
max_retries=3
)
Rate Limiting
Prevents API abuse:
client = APIClient(
base_url="http://service:8000",
token="token",
service_id="my-service",
rate_limit_requests=100,
rate_limit_window=60
)
๐ Monitoring
Each API client provides comprehensive statistics:
stats = client.get_stats()
print(f"Circuit breaker state: {stats['circuit_breaker']['state']}")
print(f"Rate limit usage: {stats['rate_limiter']['current_requests']}")
๐๏ธ Architecture
FireFeed Core follows these principles:
- API-First: All services communicate via HTTP APIs only
- Zero Direct Database Access: Services never access databases directly
- Token-Based Security: All inter-service communication is authenticated
- Fault Tolerance: Circuit breakers, retries, and rate limiting
- Consistent Error Handling: Standardized exception hierarchy
Service Communication Flow
โโโโโโโโโโโโโโโโโโโโโโโ JWT Token โโโโโโโโโโโโโโโโโโโโโโโ
โ firefeed-rss-parserโ โโโโโโโโโโโโโโโ โ firefeed-api โ
โ (Dumb Service) โ โ (Smart Service) โ
โ โ โโโโโโโโโโโโโโโ โ โ
โ - RSS Processing โ HTTP API โ - Database Access โ
โ - No DB Access โ โ - Business Logic โ
โโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ
๐งช Testing
# Install test dependencies
pip install -e ".[test]"
# Run tests
pytest
# Run with coverage
pytest --cov=firefeed_core
๐ Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
๐ License
MIT License - see LICENSE file for details.
๐ Related Projects
- FireFeed API - Main API service
- FireFeed RSS Parser - RSS processing service
- FireFeed Telegram Bot - Telegram bot service
Note: This is a core library intended for use within the FireFeed microservices ecosystem.
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 firefeed_core-1.0.1.tar.gz.
File metadata
- Download URL: firefeed_core-1.0.1.tar.gz
- Upload date:
- Size: 107.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
14ffbee83f02dd0cb0638aa07881dd5c037d4afcec04dc0c18acc1874f0c420b
|
|
| MD5 |
a842b5cb67da362a63c3ee992d890e24
|
|
| BLAKE2b-256 |
970021fb6cc1043599ec8994704751c81a92552318fa880aa6b6e9317f764dfe
|
Provenance
The following attestation bundles were made for firefeed_core-1.0.1.tar.gz:
Publisher:
release.yml on firefeed-net/firefeed-core
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
firefeed_core-1.0.1.tar.gz -
Subject digest:
14ffbee83f02dd0cb0638aa07881dd5c037d4afcec04dc0c18acc1874f0c420b - Sigstore transparency entry: 1190946653
- Sigstore integration time:
-
Permalink:
firefeed-net/firefeed-core@31a2fed24d677e78ae963d45194cb90d398098fa -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/firefeed-net
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@31a2fed24d677e78ae963d45194cb90d398098fa -
Trigger Event:
push
-
Statement type:
File details
Details for the file firefeed_core-1.0.1-py3-none-any.whl.
File metadata
- Download URL: firefeed_core-1.0.1-py3-none-any.whl
- Upload date:
- Size: 134.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a5f9856c05e0af5d1f47564c43bfee0ce7a5e0f120ecab66a43b7f73cd889834
|
|
| MD5 |
1c59682e30aae1fb3a1968e470b78740
|
|
| BLAKE2b-256 |
1d105346856bd7ad15b3ddf0164d50b4a4e9a786913c02eb22f9e3dfe8bbfde2
|
Provenance
The following attestation bundles were made for firefeed_core-1.0.1-py3-none-any.whl:
Publisher:
release.yml on firefeed-net/firefeed-core
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
firefeed_core-1.0.1-py3-none-any.whl -
Subject digest:
a5f9856c05e0af5d1f47564c43bfee0ce7a5e0f120ecab66a43b7f73cd889834 - Sigstore transparency entry: 1190946655
- Sigstore integration time:
-
Permalink:
firefeed-net/firefeed-core@31a2fed24d677e78ae963d45194cb90d398098fa -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/firefeed-net
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@31a2fed24d677e78ae963d45194cb90d398098fa -
Trigger Event:
push
-
Statement type: