Skip to main content

A package with many utility functions

Project description

winiutils

built with pyrig Python 3.12+ License: MIT Code style: ruff Type checked: mypy

A comprehensive Python utility library providing production-ready tools for data processing, concurrent execution, security, and object-oriented programming patterns.

Built with pyrig


Table of Contents


Features

  • DataFrame Cleaning Pipeline — Extensible Polars DataFrame cleaning with an 8-step pipeline
  • Concurrent Processing — Unified multiprocessing and multithreading with automatic resource optimization
  • OOP Utilities — Metaclasses and mixins for automatic method logging and instrumentation
  • Security Tools — OS keyring integration and AES-GCM encryption utilities
  • Type Safety — Full type hints with strict mypy compliance
  • Production Ready — Comprehensive test coverage and logging integration

Installation

Using uv (recommended)

uv add winiutils

Using pip

pip install winiutils

From source

git clone https://github.com/Winipedia/winiutils.git
cd winiutils
uv sync

Quick Start

DataFrame Cleaning

from winiutils.src.data.dataframe.cleaning import CleaningDF
import polars as pl

class UserDataCleaner(CleaningDF):
    """Clean and standardize user data."""

    USER_ID = "user_id"
    EMAIL = "email"
    SCORE = "score"

    @classmethod
    def get_rename_map(cls):
        return {cls.USER_ID: "UserId", cls.EMAIL: "Email", cls.SCORE: "Score"}

    @classmethod
    def get_col_dtype_map(cls):
        return {cls.USER_ID: pl.Int64, cls.EMAIL: pl.Utf8, cls.SCORE: pl.Float64}

    # ... implement other abstract methods

# Usage
cleaned = UserDataCleaner(raw_dataframe)
result = cleaned.df

Concurrent Processing

from winiutils.src.iterating.concurrent.multiprocessing import multiprocess_loop
from winiutils.src.iterating.concurrent.multithreading import multithread_loop

# CPU-bound tasks (multiprocessing)
def process_chunk(data, config):
    return heavy_computation(data, config)

results = multiprocess_loop(
    process_function=process_chunk,
    process_args=[(chunk,) for chunk in data_chunks],
    process_args_static=(config,),
    process_args_len=len(data_chunks),
)

# I/O-bound tasks (multithreading)
def fetch_url(url, headers):
    return requests.get(url, headers=headers)

results = multithread_loop(
    process_function=fetch_url,
    process_args=[(url,) for url in urls],
    process_args_static=(headers,),
    process_args_len=len(urls),
)

Automatic Method Logging

from winiutils.src.oop.mixins.mixin import ABCLoggingMixin

class MyService(ABCLoggingMixin):
    def process_data(self, data: list) -> dict:
        # Automatically logged with timing
        return {"processed": len(data)}

# Logs: "MyService - Calling process_data with (...) and {...}"
# Logs: "MyService - process_data finished with 0.5 seconds -> returning {...}"

Encryption with Keyring

from winiutils.src.security.keyring import get_or_create_aes_gcm
from winiutils.src.security.cryptography import encrypt_with_aes_gcm, decrypt_with_aes_gcm

# Get or create encryption key (stored in OS keyring)
aes_gcm, key = get_or_create_aes_gcm("my_app", "user@example.com")

# Encrypt and decrypt
encrypted = encrypt_with_aes_gcm(aes_gcm, b"Secret message")
decrypted = decrypt_with_aes_gcm(aes_gcm, encrypted)

Documentation

Full documentation is available in the docs folder:


Modules

Module Description
winiutils.src.data DataFrame cleaning pipeline and data structure utilities
winiutils.src.iterating Concurrent processing with multiprocessing and multithreading
winiutils.src.oop Metaclasses and mixins for automatic method logging
winiutils.src.security AES-GCM encryption and OS keyring integration

Development

Setup

git clone https://github.com/Winipedia/winiutils.git
cd winiutils
uv sync --all-groups

Running Tests

uv run pytest

Code Quality

# Linting
uv run ruff check .

# Type checking
uv run mypy .

# Security scanning
uv run bandit -r winiutils/

Pre-commit Hooks

uv run pre-commit install
uv run pre-commit run --all-files

Project Structure

winiutils/
├── src/                          # Main source code
│   ├── data/                     # Data processing
│   │   ├── dataframe/            # Polars DataFrame cleaning
│   │   └── structures/           # Dicts, text utilities
│   ├── iterating/                # Iteration utilities
│   │   └── concurrent/           # Multiprocessing & multithreading
│   ├── oop/                      # OOP patterns
│   │   └── mixins/               # Logging metaclass & mixin
│   └── security/                 # Security utilities
│       ├── cryptography.py       # AES-GCM encryption
│       └── keyring.py            # OS keyring integration
├── dev/                          # Development tools
│   ├── cli/                      # CLI subcommands
│   └── tests/fixtures/           # Test fixtures
├── docs/                         # Documentation
└── tests/                        # Test suite

License

This project is licensed under the MIT License - see the LICENSE file for details.


Contributing

Contributions are welcome! Please ensure:

  1. All tests pass (uv run pytest)
  2. Code passes linting (uv run ruff check .)
  3. Types are correct (uv run mypy .)
  4. New features include tests
  5. Documentation is updated for API changes

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

winiutils-2.3.4.tar.gz (24.1 kB view details)

Uploaded Source

Built Distribution

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

winiutils-2.3.4-py3-none-any.whl (36.8 kB view details)

Uploaded Python 3

File details

Details for the file winiutils-2.3.4.tar.gz.

File metadata

  • Download URL: winiutils-2.3.4.tar.gz
  • Upload date:
  • Size: 24.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for winiutils-2.3.4.tar.gz
Algorithm Hash digest
SHA256 2bb704b5e0861fe15d2f9f6fd2b086f05ca29284e5f7c115d31cded174d7cbf2
MD5 dd30e05c1afac8aa225c3e9f7cf0cc51
BLAKE2b-256 d1398f6c6278a385c993a8125c87634fde54dc43931244ff3b68ccdea4c638f2

See more details on using hashes here.

File details

Details for the file winiutils-2.3.4-py3-none-any.whl.

File metadata

  • Download URL: winiutils-2.3.4-py3-none-any.whl
  • Upload date:
  • Size: 36.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for winiutils-2.3.4-py3-none-any.whl
Algorithm Hash digest
SHA256 c3edc7614ac728b545328a911f7c76d43ca58929d106bc537d3c1a2d38a766bf
MD5 3442384acfb9a61426bc458d27ede986
BLAKE2b-256 bfaf18276ff6317b890082feaacd101e311b4baa7b165da4892b479c635e30ea

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