Skip to main content

Common utilities and configurations for MySingle Platform microservices

Project description

MySingle

Common utilities and configurations for MySingle Platform microservices.

๐Ÿ“ฆ Installation

Basic Installation

pip install mysingle

Installs only core dependencies (pydantic, pydantic-settings).

Feature-specific Installation

# Authentication features
pip install mysingle[auth]

# Web framework features
pip install mysingle[web]

# Database features
pip install mysingle[database]

# Email features
pip install mysingle[email]

# Monitoring features
pip install mysingle[monitoring]

# All features
pip install mysingle[full]

# Development tools
pip install mysingle[dev]

Combined Installation

# Web + Auth + Database
pip install mysingle[web,auth,database]

# Full features + development tools
pip install mysingle[full,dev]

๐Ÿš€ Quick Start

Basic Usage

from mysingle.core import create_fastapi_app
from mysingle.core.config import settings

# Create FastAPI app with common configurations
app = create_fastapi_app()

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8000)

๐Ÿงญ Imports: ๊ถŒ์žฅ ๊ฒฝ๋กœ

๋ฃจํŠธ ์žฌ๋…ธ์ถœ์€ ์œ ์ง€๋˜์ง€๋งŒ, ์„œ๋ธŒํŒจํ‚ค์ง€ ๊ฒฝ๋กœ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ˆœํ™˜์ฐธ์กฐ๋ฅผ ํ”ผํ•˜๊ณ  ์ดˆ๊ธฐํ™” ๋น„์šฉ์„ ์ค„์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • Core (๋ฃจํŠธ์—์„œ๋„ ๋…ธ์ถœ ์œ ์ง€)

    • ๊ถŒ์žฅ: from mysingle.core import create_fastapi_app, CommonSettings, settings, get_settings, init_mongo, get_mongodb_url, get_database_name
    • ๋ฃจํŠธ๋„ ๊ฐ€๋Šฅ: from mysingle import create_fastapi_app, CommonSettings, settings, get_settings, init_mongo, get_mongodb_url, get_database_name
  • Logging

    • ๊ถŒ์žฅ: from mysingle.logging import get_logger, setup_logging, configure_structured_logging
    • ๋ฃจํŠธ๋„ ๊ฐ€๋Šฅ: from mysingle import get_logger
  • Database

    • ๊ถŒ์žฅ: from mysingle.database import BaseDuckDBManager
    • ๋ฃจํŠธ๋„ ๊ฐ€๋Šฅ: from mysingle import BaseDuckDBManager
  • Clients

    • ๊ถŒ์žฅ: from mysingle.clients import BaseServiceClient
    • ๋ฃจํŠธ๋„ ๊ฐ€๋Šฅ: from mysingle import BaseServiceClient

๋ฃจํŠธ ํŒจํ‚ค์ง€(mysingle)๋Š” ์ง€์—ฐ ๋กœ๋”ฉ(lazy export)์œผ๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ์–ด, ์‹ฌ๋ณผ ์ ‘๊ทผ ์‹œ์ ์—๋งŒ ์„œ๋ธŒํŒจํ‚ค์ง€๋ฅผ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค.

With Authentication

from mysingle.core import create_fastapi_app
from mysingle.auth import get_user_manager
from mysingle.auth.router import auth_router

app = create_fastapi_app()
app.include_router(auth_router, prefix="/auth")

With Database

from mysingle.core import create_fastapi_app
from mysingle.core.db import init_db

app = create_fastapi_app()

@app.on_event("startup")
async def startup():
    await init_db()

๐Ÿ“‹ Features

  • ๐Ÿ” Authentication: JWT-based auth with OAuth support
  • ๐ŸŒ Web Framework: FastAPI with common configurations
  • ๐Ÿ—„๏ธ Database: MongoDB with Beanie ODM
  • ๐Ÿ“ง Email: Template-based email system
  • ๐Ÿ“Š Monitoring: Prometheus metrics and structured logging
  • โš™๏ธ Configuration: Pydantic-based settings management

๐Ÿ“ Available Dependencies by Feature

Core (always installed)

  • pydantic>=2.5.0
  • pydantic-settings>=2.1.0

Auth

  • httpx-oauth>=0.16.1
  • pyjwt>=2.10.1
  • pwdlib>=0.2.1

Web

  • fastapi>=0.104.1
  • uvicorn[standard]>=0.24.0
  • python-multipart>=0.0.6

Database

  • motor>=3.3.2
  • beanie>=1.23.6
  • redis>=6.4.0

Email

  • emails>=0.6
  • jinja2>=3.1.6

Monitoring

  • prometheus-client>=0.19.0
  • structlog>=23.2.0

๐Ÿ› ๏ธ Development

# Clone repository
git clone <repo-url>
cd quant-pack

# Install with development dependencies
pip install -e .[full,dev]

# Run tests
pytest

# Format code
black src/
ruff check src/ --fix

# Type checking
mypy src/mysingle/

๐Ÿ”– Release & Versioning

CI๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ Conventional Commits๋ฅผ ํŒŒ์‹ฑํ•ด ์ž๋™์œผ๋กœ ๋‹ค์Œ ๋ฒ„์ „์„ ๊ฒฐ์ •(major/minor/patch)ํ•ฉ๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ๋ฆด๋ฆฌ์Šค ์ „์— ์ˆ˜๋™์œผ๋กœ ๋ฒ„์ „์„ ์ง€์ •ํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด, ์ œ๊ณต๋œ ๋Œ€ํ™”ํ˜• ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์„ธ์š”. ์ด ์Šคํฌ๋ฆฝํŠธ๋กœ ์ง์ ‘ ๋ฒ„์ „์„ ์˜ฌ๋ฆฌ๋ฉด CI์˜ ์ž๋™ ๋ฒ„์ „ ๊ฒฐ์ •์€ ์Šคํ‚ต๋ฉ๋‹ˆ๋‹ค(์ˆ˜๋™ ๋ณ€๊ฒฝ ์šฐ์„ ).

๋Œ€ํ™”ํ˜• ๋ฒ„์ „ ์—… ์Šคํฌ๋ฆฝํŠธ ์‚ฌ์šฉ๋ฒ•

python scripts/bump_version.py
  • ํ˜„์žฌ ๋ฒ„์ „์„ ์ฝ์–ด์™€ bump ์ข…๋ฅ˜(major/minor/patch/custom)๋ฅผ ์„ ํƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ์˜ต์…˜์œผ๋กœ main ๋ธŒ๋žœ์น˜ ์ „ํ™˜/์ตœ์‹  ๋ฐ˜์˜, ์ปค๋ฐ‹/ํƒœ๊ทธ ์ƒ์„ฑ, ์›๊ฒฉ ํ‘ธ์‹œ๊นŒ์ง€ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.
  • ์ปค๋ฐ‹ ๋ฉ”์‹œ์ง€๋Š” chore(release): vX.Y.Z (bump <type>) ํ˜•ํƒœ๋กœ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.
  • pyproject.toml์˜ project.version์ด ๋ณ€๊ฒฝ๋˜๋ฏ€๋กœ, ๊ฐ™์€ ์ปค๋ฐ‹์—์„œ ๋‹ค์‹œ ์ž๋™ ๋ฒ„์ „ ์˜ฌ๋ฆฌ๊ธฐ๋ฅผ ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

๊ถŒ์žฅ ํ”Œ๋กœ์šฐ(์ˆ˜๋™ ๋ฆด๋ฆฌ์Šค):

  1. ํ…Œ์ŠคํŠธ/๊ฒ€ํ†  ์™„๋ฃŒ โ†’ 2) python scripts/bump_version.py ์‹คํ–‰ โ†’ 3) ์ปค๋ฐ‹/ํƒœ๊ทธ/ํ‘ธ์‹œ โ†’ 4) CI๊ฐ€ ๋นŒ๋“œ/ํผ๋ธ”๋ฆฌ์‹œ ์ˆ˜ํ–‰(์ˆ˜๋™ ๋ฒ„์ „ ์œ ์ง€)

๏ฟฝ๏ธ Roadmap

Phase 1: Enhanced Developer Experience (Current)

  • DI Functions Compatibility: Add Depends() wrapper functions for backward compatibility
  • ServiceConfig Extensions: Add ServiceCategory enum and internal routes flag
  • Configuration Documentation: Create inheritance pattern templates for services

Phase 2: Advanced Architecture (Q4 2024)

  • Service Templates: Generate service-specific configuration templates
  • Service Type Expansion: Add ORCHESTRATOR, EXECUTION, DATA, ANALYTICS, UTILITY types
  • Enhanced Routing: Support for internal vs external API separation

Phase 3: Developer Tools (Q1 2025)

  • CLI Tools: Service generator and validator commands
  • Testing Utilities: Enhanced auth helpers and service testing framework
  • Auto Documentation: Generate service documentation from configuration

Completed Features โœ…

  • App Factory Standardization: Unified FastAPI app creation with automatic middleware setup
  • HTTP Client Pooling: Standardized service-to-service communication with connection pooling
  • Structured Logging: JSON logging with correlation ID support and context management
  • Kong Gateway Integration: Complete header standardization and authentication flow
  • Metrics Collection: Prometheus-compatible metrics with performance monitoring
  • Audit Logging: Comprehensive request/response logging system

Migration Status

  • All services using App Factory pattern
  • HTTP client standardization implemented
  • Kong Gateway headers standardized
  • Structured logging system deployed
  • CommonSettings inheritance pattern adoption
  • Request-based DI pattern migration
  • Test code updates
  • Environment configuration migration

๏ฟฝ๐Ÿ“„ License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

mysingle-1.2.5-py3-none-any.whl (133.2 kB view details)

Uploaded Python 3

File details

Details for the file mysingle-1.2.5-py3-none-any.whl.

File metadata

  • Download URL: mysingle-1.2.5-py3-none-any.whl
  • Upload date:
  • Size: 133.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.7

File hashes

Hashes for mysingle-1.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 3e33599ba63f115a88ef147284c3d60a8437cfebb4a0b95f1013a339bc314bf9
MD5 0c01a3f0cc56b23f48dd53224fea2b95
BLAKE2b-256 17cf7beffa27e1265741ad0aa5de37351d422a084c19f43838343686ffea0389

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