Skip to main content

Common core library for all microservices

Project description

SAAS Core Library

Common core library for all microservices in the SAAS platform.

Features

  • Database Management: SQLAlchemy 2.0+ async engine with connection pooling
  • Redis Client: Async Redis client with state and cache databases
  • Elasticsearch: Centralized Elasticsearch client management
  • Security: JWT token management, password hashing, API key handling
  • Logging: Structured logging with service-specific loggers
  • Response Handling: Standardized API response formats
  • Configuration: Environment-based configuration management

Installation

pip install saas-core-lib

Usage

Database

from saas_core_lib import get_db_session, create_tables

# Get database session
async with get_db_session() as session:
    # Your database operations
    pass

# Create all tables
await create_tables()

Redis

from saas_core_lib import get_redis_client

# Get Redis client
redis_client = await get_redis_client()
await redis_client.set("key", "value")

Security

from saas_core_lib import hash_password, verify_password, create_access_token

# Hash password
hashed = hash_password("my_password")

# Verify password
is_valid = verify_password("my_password", hashed)

# Create JWT token
token = create_access_token({"user_id": "123"})

Response Handling

from saas_core_lib import create_success_response, create_error_response, ErrorCode

# Success response
return create_success_response("User created successfully", {"user_id": "123"})

# Error response
return create_error_response("User not found", ErrorCode.NOT_FOUND, 404)

Logging

from saas_core_lib import get_logger, LogLevel, setup_logging

# Setup logging for service
setup_logging("my-service", LogLevel.INFO)

# Get logger
logger = get_logger("my-service")
logger.info("Application started")

Configuration

Set environment variables in .env file:

# Database
DATABASE_URL=postgresql+asyncpg://user:pass@localhost/dbname

# Redis  
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=password

# Elasticsearch
ELASTICSEARCH_URL=https://localhost:9200
ELASTICSEARCH_USERNAME=user
ELASTICSEARCH_PASSWORD=pass

# JWT
JWT_SECRET=your-secret-key
JWT_ALGORITHM=HS256
JWT_EXPIRE_DAYS=7

Development

# Install dev dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Code formatting
black src/
isort src/

# Type checking
mypy src/

License

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 Distribution

saas_core_lib-0.1.3.tar.gz (24.9 kB view details)

Uploaded Source

Built Distribution

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

saas_core_lib-0.1.3-py3-none-any.whl (28.7 kB view details)

Uploaded Python 3

File details

Details for the file saas_core_lib-0.1.3.tar.gz.

File metadata

  • Download URL: saas_core_lib-0.1.3.tar.gz
  • Upload date:
  • Size: 24.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.4

File hashes

Hashes for saas_core_lib-0.1.3.tar.gz
Algorithm Hash digest
SHA256 dc94640b65d8f67c57718ab9169672c2378d61001774eb16c827fcf5ab6704f9
MD5 3e529677c96d57329d73edab9cbb3c04
BLAKE2b-256 4eebd46d98198cb726ea1981688f42243b030ad739cd19c3adeb5b286a85ea75

See more details on using hashes here.

File details

Details for the file saas_core_lib-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: saas_core_lib-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 28.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.4

File hashes

Hashes for saas_core_lib-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 383d9e13f6017767c898e32b1954bded5234b930a8e1056699e5bf469cca5941
MD5 e2baab6c36a86da9cac72bf1f34123a9
BLAKE2b-256 bcd25543dec1228b23b7ee4d1355b9c1a989880527bf48f92d2107520cd5d04e

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