Skip to main content

Common utilities for Earnbase services

Project description

Earnbase Common

A comprehensive utility package providing common functionality for Earnbase microservices.

Features

Core Components

  • Configuration Management (config/)

    • YAML-based configuration loading
    • Environment variable support
    • Pydantic settings validation
  • Database Integration (database/)

    • MongoDB async connection management
    • Connection pooling
    • Database operation utilities
  • Error Handling (errors/)

    • Standardized error classes
    • Custom exception handling
    • Error response formatting
  • HTTP Utilities (http/)

    • Request/Response handling
    • HTTP client utilities
    • API response formatting
  • Logging (logging/)

    • Structured logging with structlog
    • Log formatting and configuration
    • Log level management
  • Metrics (metrics/)

    • Prometheus metrics integration
    • Custom metrics collection
    • Monitoring utilities
  • Middleware (middleware/)

    • Request tracking
    • Authentication middleware
    • Cross-cutting concerns
  • Redis Integration (redis/)

    • Async Redis client
    • Connection management
    • Caching utilities
  • Response Handling (responses/)

    • Standardized response models
    • Success/Error response formatting
    • JSON serialization
  • Security (security/)

    • JWT token management
    • Password hashing
    • Cryptographic utilities

Installation

pdm add earnbase-common

Usage

Configuration

from earnbase_common.config import load_config

config = load_config("config.yaml")

Database

from earnbase_common.database import mongodb

await mongodb.connect(url="mongodb://localhost:27017")

Logging

from earnbase_common.logging import get_logger

logger = get_logger(__name__)
logger.info("message", extra={"key": "value"})

Redis

from earnbase_common.redis import redis_client

await redis_client.connect(url="redis://localhost:6379")

Response Models

from earnbase_common.responses import SuccessResponse

response = SuccessResponse(
    success=True,
    message="Operation successful",
    data={"key": "value"}
)

Development

Prerequisites

  • Python 3.9+
  • PDM

Setup

  1. Clone the repository
  2. Install dependencies:
pdm install

Testing

pdm run pytest

Building

pdm build

Version Compatibility

  • Python: >=3.9
  • FastAPI: >=0.104.1
  • Pydantic: >=2.5.2
  • Motor: >=3.3.2

Contributing

  1. Fork the repository
  2. Create your feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

License

MIT

Support

For support, email dev@earnbase.io

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.15.tar.gz (14.6 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.15-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

Details for the file earnbase_common-0.1.15.tar.gz.

File metadata

  • Download URL: earnbase_common-0.1.15.tar.gz
  • Upload date:
  • Size: 14.6 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.15.tar.gz
Algorithm Hash digest
SHA256 3773985c0b4072f8ffca2648b85c45fd18c0bb980a80e02eb0b8d855890845c6
MD5 d9bac2768ba70ac1a0c3a8e2a5814cf5
BLAKE2b-256 0e1f9c2260a69805534549da772a4f10a0aa9fa7d8e88aa32d43cd1de14c57aa

See more details on using hashes here.

File details

Details for the file earnbase_common-0.1.15-py3-none-any.whl.

File metadata

  • Download URL: earnbase_common-0.1.15-py3-none-any.whl
  • Upload date:
  • Size: 21.1 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.15-py3-none-any.whl
Algorithm Hash digest
SHA256 7aa99176008bd40de1aa8174d23744175227ce21f161da8edaf700ce9be17c74
MD5 68a2f30d90b938f8648b73873bd39b22
BLAKE2b-256 164ba07df9e0fe841562ee1bd4c1eb433378fc1dee059abbae7686facdfed8fe

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