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.2.0.tar.gz (20.0 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.2.0-py3-none-any.whl (24.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for yclibs-0.2.0.tar.gz
Algorithm Hash digest
SHA256 8bca37ab928e93a02a01cadd8241d22f08b350f087b6f45f6983fd31dfacce8a
MD5 df8eb9f0dcaea9f7a20d7b75a44bd915
BLAKE2b-256 a2cac7f36934f7f57db705ce63c205b121d46e4bfe7564749066f695b49496a6

See more details on using hashes here.

Provenance

The following attestation bundles were made for yclibs-0.2.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.2.0-py3-none-any.whl.

File metadata

  • Download URL: yclibs-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 24.0 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b40a4f77f44c5004a7850fdcd293524794ecf030f355a60b19583d7b1ed633ff
MD5 907a20a28e3c82da63acac6351cc1502
BLAKE2b-256 3540998b8884451e0cc9b472d6f3f66017f64fb0e170bcfb32eddd5dbfca12bd

See more details on using hashes here.

Provenance

The following attestation bundles were made for yclibs-0.2.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