Skip to main content

A collection of reusable utility functions, classes, and decorators.

Project description

Simply Useful

A Python module providing a collection of reusable utility functions, classes, and decorators to simplify development.

Features

  • Dependency Management

    • dependency_checker: Check for and install missing Python modules.
  • Terminal Utilities

    • clear_term: Clears the terminal screen.
  • Formatting Utilities

    • format_bytes: Converts bytes into a human-readable string.
    • format_uptime: Formats uptime in seconds into a readable string.
    • format_number: Formats large numbers into a readable string.
  • Signal Handling

    • handle_interrupt: Handles interrupt signals and executes a specified action.
  • Decorators

    • timeit: Logs the execution time of a function.
    • retry: Retries a function with exponential backoff.
    • cache_results: Caches the results of a function to avoid recomputation.
    • measure_memory: Measures the peak memory usage of a function.
    • async_retry: Retries an async function with exponential backoff.

Usage

Importing the Module

import simply_useful as SU

Examples

Dependency Checker

from simply_useful import dependency_checker

REQUIRED = ['boto3', 'botocore']
checker = dependency_checker(REQUIRED)
checker.check_dependencies()
status = checker.get_status()
print(f"Installed: {status['exist']}")
print(f"Missing: {status['missing']}")

Format Bytes

from simply_useful import format_bytes

print(format_bytes(1024)) 

Retry Decorator

from simply_useful import retry

@retry(max_retries=3, backoff=2.0)
def fetch_data():
    # Simulate a transient error
    if random.random() < 0.8:
        raise ValueError("Temporary failure")
    return "Success!"

print(fetch_data())

Async Retry

from simply_useful import async_retry

@async_retry(max_retries=3, backoff=2.0)
async def async_fetch_data():
    # Simulate a transient error
    if random.random() < 0.8:
        raise ValueError("Temporary failure")
    return "Success!"

asyncio.run(async_fetch_data())

License

This project is licensed under the MIT License.

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

simply_useful-1.0.0.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

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

simply_useful-1.0.0-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file simply_useful-1.0.0.tar.gz.

File metadata

  • Download URL: simply_useful-1.0.0.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for simply_useful-1.0.0.tar.gz
Algorithm Hash digest
SHA256 790e35fb90e124c15410488e5e1395edb775a7998d81f050d5c3efece23fc3c2
MD5 4d61c67c3a0dab48609d54edbead4b71
BLAKE2b-256 a689c1e99bc131ed1f78b7936d81a286986cff6bb6986dd202953fa31315e30b

See more details on using hashes here.

File details

Details for the file simply_useful-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: simply_useful-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for simply_useful-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c3ef2b842c2f76a5995bc2b012f7406c9517aac5f37024e1f859a5821c8fd68e
MD5 1e2f407937dedb2ef32e4fa74edf3353
BLAKE2b-256 dda17e184e36f40354aad0bf6f8dcbc6aa7c1b4688b5cbce99b9ad0b245bda51

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