Metadata-Version: 2.1
Name: earnbase-common
Version: 0.1.16
Summary: Common utilities for Earnbase services
Keywords: logging,utilities,microservices,fastapi,mongodb,redis
Author-Email: Earnbase Team <dev@earnbase.io>
License: MIT
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: System :: Logging
Classifier: Framework :: FastAPI
Classifier: Operating System :: OS Independent
Classifier: Typing :: Typed
Project-URL: Homepage, https://github.com/earnbaseio/earnbase-common
Project-URL: Documentation, https://github.com/earnbaseio/earnbase-common#readme
Project-URL: Source Code, https://github.com/earnbaseio/earnbase-common
Project-URL: Bug Tracker, https://github.com/earnbaseio/earnbase-common/issues
Project-URL: Changelog, https://github.com/earnbaseio/earnbase-common/blob/main/CHANGELOG.md
Requires-Python: >=3.9
Requires-Dist: pydantic>=2.5.2
Requires-Dist: fastapi>=0.104.1
Requires-Dist: motor>=3.3.2
Requires-Dist: redis>=5.0.1
Requires-Dist: structlog>=23.2.0
Requires-Dist: prometheus-client>=0.19.0
Requires-Dist: pyjwt>=2.8.0
Requires-Dist: pyyaml>=6.0.1
Requires-Dist: httpx>=0.26.0
Requires-Dist: bcrypt>=4.2.1
Requires-Dist: pytest-asyncio>=0.25.2
Requires-Dist: anyio>=4.8.0
Description-Content-Type: text/markdown

# 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 serialization
  - `DomainEvent`: Event tracking with automatic type assignment
  - `AggregateRoot`: Aggregate root pattern with event management

- **Value Objects**
  - `Email`: Email validation and formatting
  - `PasswordHash`: Secure password hash handling
  - `Token`: JWT token management with expiration
  - `PhoneNumber`: Phone number validation with country codes
  - `Money`: Currency handling with validation
  - `Address`: 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

```bash
pdm add earnbase-common
```

## Quick Start

```python
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](docs/models.md): Domain models and aggregates
- [Value Objects](docs/value-objects.md): Immutable value objects
- [Security](docs/security.md): Security features and policies
- [Metrics](docs/metrics.md): Metrics collection and monitoring

## Contributing

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. 