Skip to main content

🛠️ Pyutils Collection

PyPI version Python versions License: MIT

Python utilities - 500+ functions across 31 specialized modules for async operations, data processing, file handling, security, and more.

🎯 What is This?

A collection of 500+ utility functions across 31 specialized modules, designed for copy-paste reuse or pip install. Functions include type hints, docstrings, and focused tests.

Philosophy:

  • 📋 Copy-paste friendly - Functions work standalone
  • 🔒 Type-safe - Complete type hints (Python 3.15+)
  • 📝 Self-documenting - NumPy-style docstrings with examples
  • ✅ Tested - 5,500+ unit tests; measured coverage and skips are recorded in the maintenance plan
  • 🎨 Optional browser support - Install the Playwright extra for browser utilities

📦 Quick Start

# Install from PyPI
pip install pyutils-collection

# Or clone and copy what you need
git clone https://github.com/MForofontov/pyutils-collection.git
cd pyutils-collection/pyutils_collection

# Or install for development
pip install -e ".[dev]"

📦 Modules Overview

Companion utilities

from datetime import date

from pyutils_collection.iterable_functions import unique_by, unflatten_dict, deep_delete
from pyutils_collection.datetime_functions import date_range
from pyutils_collection.url_functions import remove_query_params
from pyutils_collection.file_functions import atomic_write_file
from pyutils_collection.asyncio_functions import async_map_limited
from pyutils_collection.env_config_functions import validate_env_vars

unique_by(["Ada", "ADA", "Grace"], str.lower)  # ["Ada", "Grace"]
data = unflatten_dict({"user_name": "Ada", "user_age": 36})
deep_delete(data, "user.age")  # data is now {"user": {"name": "Ada"}}
list(date_range(date(2026, 1, 1), date(2026, 1, 4)))  # Stop is exclusive
remove_query_params("/search?q=python&utm_source=mail", ["utm_source"])
atomic_write_file("settings.json", '{"enabled": true}')
config = validate_env_vars(
    {"PORT": int, "DEBUG": bool},
    defaults={"PORT": 8080, "DEBUG": False},
)

async def double(value: int) -> int:
    return value * 2

# In an async function: await async_map_limited(double, range(100), limit=5)

unflatten_dict rejects conflicting paths and uses the same separator as flatten_dict. atomic_write_file requires an existing parent directory and uses temporary-file permissions. Environment defaults are already-converted values; malformed present values raise an error instead of using a default.

Selected utility families

Module Count Description
🔄 asyncio_functions 17 Async/await, connection pools, rate limiting, HTTP
🗜️ compression_functions 27 GZIP, BZ2, LZMA, Snappy, Zstandard, polyline encoding
🗄️ database_functions 23 SQLAlchemy utils, transactions, schema inspection
📅 datetime_functions 27 Timezone conversion, business days, humanization
🎨 decorators 50+ Caching, retry, timeout, type checking, profiling
📁 file_functions 32 I/O, hashing, search, temp files, format conversion
🌐 http_functions 9 REST operations, downloads, query strings
🔄 iterable_functions 55 Chunking, filtering, grouping, flattening
🧮 mathematical_functions 5 GCD, LCM, primes, factorial, fibonacci
🔐 security_functions 12 Encryption (AES/RSA), hashing, JWT tokens
📊 serialization_functions 28 CSV, Excel, Parquet with streaming & conversion
🔌 ssh_functions 12 Remote execution, SFTP, key generation
🧪 testing_functions 24 Fixtures, mocks, assertions, test data generators
🌍 network_functions 28 IP utilities, DNS, port scanning, connectivity
🌐 web_scraping_functions 18 HTML/CSS/XPath parsing, table extraction
🎭 playwright_functions 6 Browser automation, screenshots, session management
🔗 url_functions 8 Parse, build, validate, normalize URLs
regex_functions 5 Email/phone/URL validation & extraction
⚙️ cli_functions 16 System info, process management, environment vars
📝 logger_functions 7 Logger setup, function logging, rotation
🔄 multiprocessing_functions 19 Parallel processing, pool management
🔧 batch_processing_functions 2 Chunked processing, streaming aggregation
🌿 env_config_functions 6 Config loading (env, YAML, TOML)
✅ data_validation Many Type/schema validation, Pydantic/Cerberus support

🔑 Key Features

Database-Agnostic Design

All database functions use SQLAlchemy for maximum portability:

  • ✅ PostgreSQL
  • ✅ MySQL / MariaDB
  • ✅ SQLite
  • ✅ Oracle
  • ✅ SQL Server

Type Safety

  • Complete type hints using modern Python syntax (list[str], dict[str, Any])
  • Runtime type checking with decorators
  • mypy-compliant codebase

Comprehensive Testing

  • Package coverage reports include paths not exercised on the current platform
  • 5,500+ unit tests across the utility families
  • Pytest-based testing framework
  • Comprehensive edge case coverage

Documentation

  • NumPy-style docstrings for all functions
  • Examples in docstrings
  • Time/space complexity notes for algorithms
  • Comprehensive README with usage examples

📚 Usage Examples

Database Operations

from sqlalchemy import create_engine, text
from pyutils_collection.database_functions import atomic_transaction
from pyutils_collection.database_functions.schema_inspection import (
    get_table_info, find_duplicate_rows,
)

engine = create_engine("sqlite:///:memory:")
try:
    with engine.connect() as conn:
        with atomic_transaction(conn):
            conn.execute(text("CREATE TABLE users (id INTEGER PRIMARY KEY, email TEXT)"))
            conn.execute(
                text("INSERT INTO users (email) VALUES (:email)"),
                [{"email": "ada@example.com"}, {"email": "ada@example.com"}],
            )
        print(get_table_info(conn, "users"))
        print(find_duplicate_rows(conn, "users", ["email"]))
finally:
    engine.dispose()

Async Operations

import asyncio
from pyutils_collection.asyncio_functions import async_batch, async_map_limited

async def double_batch(items: list[int]) -> list[int]:
    return [item * 2 for item in items]

async def double(item: int) -> int:
    return item * 2

async def main() -> None:
    print(await async_batch(double_batch, list(range(5)), batch_size=2))
    print(await async_map_limited(double, range(5), limit=2))

asyncio.run(main())

Decorators

from pyutils_collection.decorators import cache, retry, timeout, enforce_types

@cache
@retry(max_retries=3, delay=0.01)
@timeout(seconds=30)
@enforce_types()
def fetch_user_data(user_id: int) -> dict:
    # Function logic here
    return {"id": user_id, "name": "John"}

File Operations

from pathlib import Path
from tempfile import TemporaryDirectory
from pyutils_collection.file_functions import (
    atomic_write_file, read_lines, calculate_sha256_hash, find_files_by_pattern,
)

with TemporaryDirectory() as directory:
    path = Path(directory) / "data.txt"
    atomic_write_file(str(path), "first line\nsecond line\n")
    print(read_lines(str(path)))
    print(calculate_sha256_hash(str(path)))
    print(find_files_by_pattern(directory, "*.txt"))

Data Serialization

from pathlib import Path
from tempfile import TemporaryDirectory
from pyutils_collection.serialization_functions import stream_csv_chunks, csv_to_parquet

with TemporaryDirectory() as directory:
    source = Path(directory) / "scores.csv"
    destination = Path(directory) / "scores.parquet"
    source.write_text("name,score\nAda,10\nGrace,12\n", encoding="utf-8")
    for chunk in stream_csv_chunks(str(source), chunk_size=1):
        print(chunk)
    print(csv_to_parquet(str(source), str(destination), compression="snappy"))

📋 Requirements

  • Python: 3.15+
  • Use a Python build that includes compression.zstd; official CPython builds provide it. Zstandard helpers now use this standard-library implementation, preserving support for previously compressed data.
  • A package installation installs the dependencies declared in pyproject.toml, including scientific, database, SSH, and security libraries.
  • Browser automation is optional: install with pip install '.[playwright]' from a checkout or pip install 'pyutils-collection[playwright]' from PyPI.

Maintenance behavior changes

Paramiko SSH helpers verify server keys against ~/.ssh/known_hosts and reject unknown or changed keys. CLI SSH helpers use the system client's host-key policy and reject option-like destinations. HTTP helpers accept only HTTP(S) URLs and redirects, stripping credentials when a redirect changes origin. Bcrypt hashing rejects passwords over 72 UTF-8 bytes, and verification returns False for those passwords. Parquet partitioning preserves null groups and raises ValueError before writing files when partition values produce colliding filenames.

Security dependency updates require modern SSH algorithms; Paramiko 5 no longer supports SHA-1 signatures/key exchange or DSA keys. Python 3.15 is now the minimum supported version. Installations on older Python versions are intentionally rejected. See the maintenance plan for migration evidence and remaining release checks.

Public function parameters remain unchanged. See CHANGELOG.md for the full list of corrections.

Async downloads preserve existing destinations on failure. Async-pool capacity includes checked-out connections; duplicate registration and foreign or duplicate release raise ValueError. ZIP extraction rejects unsafe member paths and existing symlink escapes; TAR extraction preflights members before writing.

🧪 Testing

# Install development dependencies
python -m pip install -e '.[dev]'

# Unit tests and package coverage
python scripts/run_with_deadline.py --seconds 900 --log .major-check/unit.log -- python -m pytest pytest/unit --cov=pyutils_collection --cov-report=html --junitxml=.major-check/unit.xml

# Separate performance checks and optional stress tests
python -m pytest pytest/performance -m 'performance and not slow'
python -m pytest pytest/performance -m 'performance and slow'

# Isolated local HTTP integration checks
python -m pytest pytest/integration -q

# Audit inventory, Python 3.15 wheels, and repeatable async-map benchmarks
python scripts/audit_inventory.py .major-check/unit.xml
python scripts/check_python315_wheels.py
python scripts/benchmark_async_map.py
python scripts/benchmark_sqlite_migration.py

# Static checks
python -m ruff check pyutils_collection scripts
python -m ruff format --check pyutils_collection scripts
python -m mypy pyutils_collection --install-types --non-interactive

See MAINTENANCE_PLAN.md for verified results, platform coverage, and outstanding audit work. Skipped tests and unavailable integration checks are listed separately from passes.

🤝 Contributing

See .github/copilot-instructions.md for detailed guidelines:

  • NumPy-style docstrings with examples
  • Complete type hints (Python 3.15+ syntax)
  • 95%+ test coverage per function
  • Self-contained, copy-paste friendly code

📄 License

MIT © 2026 Mykyta Forofontov

See LICENSE for the full license text.

👤 Author

Mykyta Forofontov


⭐ Star this repository if you find it useful!

Metadata

Release files for pyutils-collection 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyutils-collection 0.2.0
File Size Uploaded Provenance Actions
pyutils_collection-0.2.0.tar.gz 352.5 kB With provenance Details for pyutils_collection-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyutils-collection 0.2.0
File Interpreter ABI Platform Actions
pyutils_collection-0.2.0-py3-none-any.whl Python 3 none any Details for pyutils_collection-0.2.0-py3-none-any.whl

Total release size: 1.0 MB

Release files / pyutils_collection-0.2.0.tar.gz

Download URL pyutils_collection-0.2.0.tar.gz
Size 352.5 kB
Tags Source
SHA-256 checksum
How to use checksums
2a8a20e1744bedf50a7ec399d2c333d50cc87e52acadbadce2a3bef49ff434f0
BLAKE2b-256 checksum
How to use checksums
e86f5138a926bb982c476dc9250be319a1124f806ba313baef93dd0e750796bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 30, 2026.

Transparency log

Release files / pyutils_collection-0.2.0-py3-none-any.whl

Download URL pyutils_collection-0.2.0-py3-none-any.whl
Size 673.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
31e3c27f1dcc96c5fec35157d2fae13708e45dbb74f88650a3944305f79af10b
BLAKE2b-256 checksum
How to use checksums
8d5e224dc8313f23a3e4a15c8f79482f1606b2e9a7757e945787af4a8d6f48bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 30, 2026.

Transparency log

Security for pyutils-collection 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pyutils_collection-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 30, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page