Skip to main content

Shared Python utilities and helpers for database and date operations.

Project description

YCLibs

Shared Python utilities for database and date operations

PyPI Python License


A production-ready Python library for database operations (SQLAlchemy 2.0+, sync/async) and date utilities. Built for FastAPI projects and modern Python 3.13+.

Features

  • Database — SQLAlchemy 2.0+ with PostgreSQL (psycopg3, asyncpg)
    • Sync and async managers with type-safe CRUD
    • Connection pooling, DatabaseConfig for flexible setup
    • Declarative models with Mapped / mapped_column
  • Date — DateHelper for common date operations
    • Relative dates (yesterday, last week, last month)
    • Ranges (week, month, quarter, year)
    • Business day calculations
    • Date comparisons and formatting
  • Typed — Full PEP 484 type hints
  • Tested — pytest, optional dev tooling (ruff)

Installation

# Using uv (recommended)
uv add yclibs

# Or pip
pip install yclibs

Requirements: Python 3.13+

Quick Start

Database

from yclibs.database.database import (
    Base,
    DatabaseConfig,
    DatabaseManager,
    get_db_session,
)
from yclibs.database.models import MyModel

# Custom config (optional)
config = DatabaseConfig(
    host="localhost",
    database="mydb",
    username="user",
    password="secret",
)
db = DatabaseManager(config)

# Or use defaults
with db.session() as session:
    result = db.get_all(MyModel, limit=10)

# Context manager
with get_db_session() as session:
    item = session.get(MyModel, 1)

Async

from yclibs.database.database import AsyncDatabaseManager

async with AsyncDatabaseManager() as db:
    items = await db.get_all(MyModel, limit=10)

DateHelper

from yclibs.date.date_helper import DateHelper, Weekday
from datetime import date

dh = DateHelper()

# Relative dates
yesterday = dh.yesterday()
last_week = dh.same_day_last_week()

# Ranges
start, end = dh.current_month_range()
quarter_start, quarter_end = dh.current_quarter_range()

# Business days
next_business = dh.next_business_day()

# Reference date
dh = DateHelper(date(2025, 1, 15))
week_start = dh.start_of_week(Weekday.MONDAY)

Project Structure

yclibs/
├── database/           # SQLAlchemy 2.0 layer
│   ├── database.py     # DatabaseManager, AsyncDatabaseManager, Base, DatabaseConfig
│   └── models.py       # Base model definitions
├── date/               # Date utilities
│   └── date_helper.py  # DateHelper
└── configs/            # Default settings

Configuration

DatabaseConfig supports:

  • Individual params: host, port, database, username, password
  • Full URL: url="postgresql+psycopg://user:pass@host:5432/db"
  • Pool options: pool_size, max_overflow, pool_pre_ping, echo, etc.

Development

# Clone and install with dev deps
git clone https://github.com/Shiftryon/YCLibs.git
cd YCLibs
uv sync

# Run tests
uv run pytest

# Lint / format
uv run ruff check . && uv run ruff format .

License

MIT © Shiftryon

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

yclibs-0.1.0.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

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

yclibs-0.1.0-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

Details for the file yclibs-0.1.0.tar.gz.

File metadata

  • Download URL: yclibs-0.1.0.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for yclibs-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2c0a5fbdd7f2c4b8b1f598312a7a17a79dd23aff401025dc95c063c29e072d2b
MD5 0301ab90386b516e99c02d56e1a2ae3c
BLAKE2b-256 e9fc709f128254b1f6d84a1a931f8fef33c2544478e80e99e566dfb02268ee64

See more details on using hashes here.

Provenance

The following attestation bundles were made for yclibs-0.1.0.tar.gz:

Publisher: python-publish.yml on SHIFTRYON/YCLibs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file yclibs-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: yclibs-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for yclibs-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2c6d59585fd89ba4e193dc10ca1e29e1752cba99aa7ef7d51d4bf95501233f1a
MD5 5aad93ff28b7b68f547294d8bbd4c567
BLAKE2b-256 caa4522071832d2095d0f5e22582e0b00cdd581013b506016282703747b9cb9f

See more details on using hashes here.

Provenance

The following attestation bundles were made for yclibs-0.1.0-py3-none-any.whl:

Publisher: python-publish.yml on SHIFTRYON/YCLibs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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