Skip to main content

An open-source python package with multiple python tools.

Project description

AgGarage

An open-source python package with multiple python tools.

Installation

pip install aggarage

Usage

from aggarage import *

@blitz # Example of a decorator from the package, it optimizes heavy calculations
def heavy_calc(x):
    total = 0
    for i in range(x):
        total += i ** 2
    return total

print(heavy_calc(10_000_000))

Timed Variables

AgGarage allows you to store variables over time and retrieve past values.

from aggarage import create_timed_variable, get_value_of_timed_variable, clear_all_timed_variables

create_timed_variable("score", 100)
create_timed_variable("score", 200)

print(get_value_of_timed_variable("score"))       # latest value
print(get_value_of_timed_variable("score", "-1m")) # value 1 minute ago

clear_all_timed_variables()  # removes all timed variable data

Utilities

AgGarage also provides common utility functions:

fib(n) – Fibonacci number factorial(n) / factorial_recursive(n) – Factorial is_prime(num) – Prime check gcd(a, b) / lcm(a, b) – Greatest/common divisors reverse_string(s) / is_palindrome(s) – String utilities sum_of_squares(n) – Sum of squares printf(text, color="red") – Colored terminal output

Notes

Timed variables are stored with second-level precision and automatically prune entries older than 30 minutes. The @blitz decorator uses JIT compilation if available or threads as a fallback to speed up computations.

lightning

The @lightning decorator uses aggressive parallelization and multiprocessing to optimize performance for CPU-bound tasks. It is much faster than @blitz for heavy computations but has more overhead, so it is best suited for very intensive tasks. Use @lightning when you need maximum speedup for complex calculations that can be parallelized.

from aggarage import *

@lightning
def _heavy_computation_lightning(n):
        total = 0
        for i in range(n):
            total += sum(j * j for j in range(1000))
        return total

@blitz
def _heavy_computation_blitz(n):
        total = 0
        for i in range(n):
            total += sum(j * j for j in range(1000))
        return total

if __name__ == "__main__":
    import time

    n = 1000

    start = time.time()
    result_lightning = _heavy_computation_lightning(n)
    end = time.time()
    print(f"Lightning result: {result_lightning}, Time taken: {end - start:.4f} seconds")

    start = time.time()
    result_blitz = _heavy_computation_blitz(n)
    end = time.time()
    print(f"Blitz result: {result_blitz}, Time taken: {end - start:.4f} seconds")

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

aggarage-0.3.0.tar.gz (2.0 MB view details)

Uploaded Source

Built Distribution

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

aggarage-0.3.0-py3-none-any.whl (79.3 kB view details)

Uploaded Python 3

File details

Details for the file aggarage-0.3.0.tar.gz.

File metadata

  • Download URL: aggarage-0.3.0.tar.gz
  • Upload date:
  • Size: 2.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.0

File hashes

Hashes for aggarage-0.3.0.tar.gz
Algorithm Hash digest
SHA256 3703de3e557c0a5fd6f1fb7e75d94f6e5a9d5455005786c884048cffa0201d9a
MD5 8d4985b81e478287a0d87772c7e07321
BLAKE2b-256 b5ccecbdd628aef4cf451e83400b5a162e2db31246479191d790134dc383f0ed

See more details on using hashes here.

File details

Details for the file aggarage-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: aggarage-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 79.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.0

File hashes

Hashes for aggarage-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 df0f3b34317a60d5b19e10e9cb2cbce5da48510b1e68d1fc1b96c2b87f12c2e5
MD5 ed5012e0295069ae1974762d52cb8f3a
BLAKE2b-256 a8e946c061654fd4c8592c61cc749add8412dfb812c4e5810f30e41baee11907

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