Common utilities for Earnbase services
Project description
Earnbase Common
Core library for Earnbase Platform services.
Overview
Earnbase Common provides shared components, utilities, and standards for building microservices in the Earnbase Platform. It implements common patterns and best practices to ensure consistency across services.
Features
Domain-Driven Design Components
-
Base Models
BaseModel: Foundation for all domain models with JSON serializationDomainEvent: Event tracking with automatic type assignmentAggregateRoot: Aggregate root pattern with event management
-
Value Objects
Email: Email validation and formattingPasswordHash: Secure password hash handlingToken: JWT token management with expirationPhoneNumber: Phone number validation with country codesMoney: Currency handling with validationAddress: Address formatting and validation
Security
-
Password Management
- Strong password validation with configurable policies
- Secure hashing using bcrypt
- Password verification utilities
-
Token Management
- JWT token creation and validation
- Support for access and refresh tokens
- Configurable token expiration policies
Metrics & Monitoring
-
Prometheus Integration
- Counter, Histogram, Gauge, Summary metrics
- Custom metric decorators
- Standardized metric naming
-
Decorators
@metrics_decorator.counter: Count method calls@metrics_decorator.histogram: Measure execution time
Database & Caching
- MongoDB client with connection pooling
- Redis client for caching
- Repository pattern implementations
Error Handling
- Standard error types
- Error response formatting
- Validation error handling
Installation
pdm add earnbase-common
Quick Start
from earnbase_common.models import BaseModel
from earnbase_common.value_objects import Email, Money
from earnbase_common.security import SecurityPolicy, TokenManager
from earnbase_common.metrics import metrics_decorator
# Define a domain model
class User(BaseModel):
email: Email
balance: Money
is_active: bool = True
# Use security policies
security_policy = SecurityPolicy()
min_length = security_policy.PASSWORD_MIN_LENGTH
# Track metrics
@metrics_decorator.histogram("method_duration_seconds", ["method", "status"])
async def process_user(user: User):
# Your code here
pass
Documentation
Detailed documentation is available in the docs directory:
- Models: Domain models and aggregates
- Value Objects: Immutable value objects
- Security: Security features and policies
- Metrics: Metrics collection and monitoring
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
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 earnbase_common-0.1.16.tar.gz.
File metadata
- Download URL: earnbase_common-0.1.16.tar.gz
- Upload date:
- Size: 19.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.22.1 CPython/3.10.16 Linux/6.8.0-49-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
74d7bc80794a67359960195522886e6c6b0bbc5b13a05dacd41d1a02fd4172cc
|
|
| MD5 |
b119b6173e3684aeacbfbfc1f865a8b2
|
|
| BLAKE2b-256 |
50fab46a1e7d86b03534c4b54dc9ed90066e4f66a865e146f101cee4b365cdfa
|
File details
Details for the file earnbase_common-0.1.16-py3-none-any.whl.
File metadata
- Download URL: earnbase_common-0.1.16-py3-none-any.whl
- Upload date:
- Size: 27.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.22.1 CPython/3.10.16 Linux/6.8.0-49-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c384236ba77f616556999285e4f7fb8a00ddb6fb01e2659c213e0903c6ab9b13
|
|
| MD5 |
659097e7a0ac1ce1caa84ad4088f9175
|
|
| BLAKE2b-256 |
5078b971d69c2411214f97b30453bce59d8c5b972f5325a3eb1e5854b3be1757
|