Skip to main content

Hnady python functions

Project description

lionfuncs

License: MIT

A Python utility library for robust asynchronous programming, file system operations, and network interactions.

Overview

lionfuncs provides a core set of reusable utilities designed to simplify common programming tasks with a focus on reliability and performance. It offers a comprehensive suite of tools for asynchronous operations, file system interactions, network calls, concurrency management, error handling, and general utilities.

Key Features

  • Async Utilities: Powerful tools like alcall and bcall for concurrent execution with fine-grained control
  • Concurrency Management: Primitives such as BoundedQueue and WorkQueue for managing concurrent workloads
  • File System Operations: Utilities for reading, writing, and processing files with both sync and async APIs
  • Network Client: Resilient HTTP client with built-in circuit breaker, retry, and rate limiting capabilities
  • Error Handling: Standardized error types and handling mechanisms
  • Media Processing: Optional utilities for working with images and PDFs

Installation

Basic Installation

pip install lionfuncs

Installation with Media Utilities

To use the media utilities (e.g., pdf_to_images), install with the media extra:

pip install lionfuncs[media]

Quick Start

Asynchronous Operations

import asyncio
from lionfuncs.async_utils import alcall

async def process_item(item):
    await asyncio.sleep(0.1)  # Simulate some async work
    return item * 2

async def main():
    items = [1, 2, 3, 4, 5]
    # Process all items concurrently with a max concurrency of 3
    results = await alcall(items, process_item, max_concurrent=3)
    print(results)  # [2, 4, 6, 8, 10]

asyncio.run(main())

File System Operations

import asyncio
from lionfuncs.file_system import read_file, save_to_file

async def main():
    # Read a file
    content = await read_file("example.txt")

    # Process the content
    processed_content = content.upper()

    # Save the processed content
    await save_to_file(processed_content, "output", "example_processed.txt")

asyncio.run(main())

Network Operations

import asyncio
from lionfuncs.network import AsyncAPIClient, circuit_breaker, with_retry

# Apply resilience patterns with decorators
@circuit_breaker(failure_threshold=3, recovery_time=10.0)
@with_retry(max_retries=3, base_delay=1.0, backoff_factor=2.0)
async def fetch_data(client, endpoint):
    return await client.request("GET", endpoint)

async def main():
    async with AsyncAPIClient(base_url="https://api.example.com") as client:
        data = await fetch_data(client, "/data")
        print(data)

asyncio.run(main())

Documentation

For comprehensive documentation, including detailed API references and usage guides, visit:

Contributing

We welcome contributions to lionfuncs! Please see our Contribution Guidelines for details on how to get started, coding standards, and the pull request process.

License

lionfuncs is licensed under the MIT License. See the LICENSE file for details.

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

lionfuncs-3.0.0.tar.gz (244.6 kB view details)

Uploaded Source

Built Distribution

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

lionfuncs-3.0.0-py3-none-any.whl (37.3 kB view details)

Uploaded Python 3

File details

Details for the file lionfuncs-3.0.0.tar.gz.

File metadata

  • Download URL: lionfuncs-3.0.0.tar.gz
  • Upload date:
  • Size: 244.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.17

File hashes

Hashes for lionfuncs-3.0.0.tar.gz
Algorithm Hash digest
SHA256 c530f595a0582d1ac8accfcf763e48411445f4487acabe535f9a9b0ae540dbbc
MD5 f033ee01c4af406c302b3caf7fc939cf
BLAKE2b-256 a65f469a017b15ac8c304073c95677a5187247d5c5acb627153c28117fefee4a

See more details on using hashes here.

File details

Details for the file lionfuncs-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: lionfuncs-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 37.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.17

File hashes

Hashes for lionfuncs-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 36c9e0e4cdac8209c1ef75d44c3b5097354f69f3df6e9c3c577933873bdb69f1
MD5 0b4411ed626479f4f51b04c06a7d871c
BLAKE2b-256 36533e354c3b4a0315099a816f88db730ffe0d1af99c4d9a8986d63f2a28142b

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