Skip to main content

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 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

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:

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 file for details.

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

earnbase_common-0.1.16.tar.gz (19.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

earnbase_common-0.1.16-py3-none-any.whl (27.4 kB view details)

Uploaded Python 3

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

Hashes for earnbase_common-0.1.16.tar.gz
Algorithm Hash digest
SHA256 74d7bc80794a67359960195522886e6c6b0bbc5b13a05dacd41d1a02fd4172cc
MD5 b119b6173e3684aeacbfbfc1f865a8b2
BLAKE2b-256 50fab46a1e7d86b03534c4b54dc9ed90066e4f66a865e146f101cee4b365cdfa

See more details on using hashes here.

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

Hashes for earnbase_common-0.1.16-py3-none-any.whl
Algorithm Hash digest
SHA256 c384236ba77f616556999285e4f7fb8a00ddb6fb01e2659c213e0903c6ab9b13
MD5 659097e7a0ac1ce1caa84ad4088f9175
BLAKE2b-256 5078b971d69c2411214f97b30453bce59d8c5b972f5325a3eb1e5854b3be1757

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page