Skip to main content

A Python utility library for math, algebra, data structures, and everyday tools

Project description

eapy

A Python utility library that extends the standard library with math, algebra, data structures, and everyday tools.

Features

Math & Algebra

  • VectorVector2D, Vector3D, and N-dimensional Vector with arithmetic, dot product, magnitude, coordinate conversions
  • Matrix — 2D matrix operations (add, subtract, multiply, divide, power) with N×N determinant
  • Tensor — 3D tensor with arithmetic, slicing, transpose
  • Polynomial — polynomial arithmetic, evaluation (Horner's method), derivative, integral
  • Complex — complex number arithmetic, conjugate, phase, polar conversion
  • Symbolic AlgebraVar for building symbolic expressions with simplify & evaluate
  • InfiniteSet / Interval — set operations on numeric intervals

Trigonometry

  • Full set: sin, cos, tan, sec, csc, cot
  • Inverse: asin, acos, atan, atan2, asec, acsc, acot
  • Hyperbolic: sinh, cosh, tanh, asinh, acosh, atanh
  • Versed: versine, vercosine, coversine, covercosine

Combinatorics & Number Theory

  • permutation, combination, catalan, stirling2
  • gcd, lcm, isPrime, fibonacci, digitsSum
  • eulerTotient, primeFactors, modPow

Statistics

  • mean, median, variance, std, mode

String Utilities

  • Name conversion: toCamelCase, toSnakeCase, toPascalCase
  • levenshtein — edit distance between two strings

Functional Programming

  • pipe(value, f, g, h) — pipeline: h(g(f(value)))
  • compose(f, g, h)(x) — composition: f(g(h(x)))
  • curry(func)(a)(b)(c) — currying

Data Structures

  • Stack — LIFO stack (push/pop/peek)
  • Queue — FIFO queue (enqueue/dequeue)
  • Trie — prefix tree (insert/search/words_with_prefix)
  • LinkedList — singly linked list (append/prepend/remove/find)
  • CircularBuffer — fixed-size circular buffer
  • PriorityQueue — min-heap priority queue

Base Conversion

  • baseConvert(n, from_base, to_base) — arbitrary base conversion (2-36)
  • toBinary, toOctal, toHex — quick conversions

Color Utilities

  • rgbToHsl / hslToRgb — RGB ↔ HSL conversion
  • rgbToHex / hexToRgb — RGB ↔ HEX conversion

Numerical Methods

  • bisect(f, a, b) — bisection root finding
  • newtonMethod(f, f', x0) — Newton's method
  • numericalIntegral(f, a, b) — Simpson's rule integration

Utility & Decorators

  • Timer — simple stopwatch timer
  • clamp, lerp, mapRange — numeric helpers
  • flatten, chunk, deepGet, uniqueId — data helpers
  • @retry, @memoize, @deprecated, @singleton — decorators
  • printTable — formatted console table output
  • getPath — interactive file/directory picker
  • repeatUntilSecond, repeatUntilSecondOrBool, repeatUntilValueChange — loop helpers

Broadcast / Messaging

  • whenGetMessage, broadcast, broadcastWithData — simple event system

Threads

  • newThread, startThreads, deleteThread — simple thread management

Validation

  • isEmail, isURL, isIP — common format validators

Date Utilities

  • daysBetween, isLeapYear, weekday — date helpers

Progress Bar

  • ProgressBar — simple terminal progress bar

Hash Utilities

  • md5, sha256, hashFile — quick hashing

Random Utilities

  • randomChoice, shuffle, randomString, randomInt, randomFloat — enhanced random helpers

File I/O

  • readJson, writeJson — JSON file helpers
  • readCsv, writeCsv — CSV file helpers

Encoding

  • base64Encode, base64Decode — Base64 encoding
  • urlEncode, urlDecode — URL encoding

Math Extensions

  • factorial — factorial
  • matrixInverse — matrix inverse (Gauss-Jordan)
  • interpolate — linear interpolation

Regex Utilities

  • extractEmails, extractURLs — extract from text
  • replaceMultiple — multi-pattern replacement

Cache & Performance

  • @lruCache(maxsize) — LRU cache decorator
  • @timeit — execution time decorator

Progress Iterator

  • tqdm(iterable) — progress bar iterator

Type Checks

  • isNumber, isString, isList, isDict, isCallable — type check helpers

Network Utilities

  • getJson(url) — GET request returning JSON
  • postJson(url, data) — POST request with JSON body

Math Extensions (Vector)

  • dotProduct, crossProduct, normalize — vector operations

Local Storage

  • Storage — persistent key-value store with subpath support

Colored Text

  • Color — ANSI color codes (foreground, background, styles)
  • colorText(text, color, style, bg) — return colored text string
  • printColor(text, color, style, bg) — print colored text

Logging

  • Logger — simple logger (console + file)
  • @logTime — log function calls with timing

Config Management

  • Config — JSON-based config with dot notation support

Validation (Extended)

  • isPhoneNumber — Chinese phone number validation
  • isDate — date format validation
  • isHexColor — hex color validation

File Utilities

  • listFiles(dir, ext) — list files by extension
  • fileSize(path) — human-readable file size
  • ensureDir(path) — create directory if not exists

CLI Interaction

  • confirm(prompt) — yes/no confirmation
  • askInput(prompt, default) — input with default
  • selectOption(prompt, options) — selection menu

Encryption

  • encrypt(text, key) / decrypt(text, key) — simple XOR encryption

Time Utilities

  • formatDuration(seconds) — human-readable duration
  • timestamp() — current Unix timestamp
  • parseDate(str, fmt) — parse date string

Installation

pip install eapyTool

Quick Start

from eapy.core import Var, Polynomial, Vector3D, mean

# Symbolic algebra
x = Var('x')
expr = (x + 2) * (x + 3)
print(expr.evaluate(x=5))  # 56.0

# Polynomial
p = Polynomial([1, -3, 2])  # 1 - 3x + 2x^2
print(p.derivative())        # -3 + 4*x
print(p(10))                 # 171.0

# Vector
v = Vector3D(1, 2, 3)
print(v.abs())               # 3.7416...

# Statistics
print(mean([4, 8, 15, 16, 23, 42]))  # 18.0

Development

# install with dev dependencies
pip install -e ".[dev]"

# run tests
pytest

# lint
ruff check src tests
ruff format --check src tests

License

MPL-2.0

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

eapytool-0.3.3.tar.gz (35.0 kB view details)

Uploaded Source

Built Distribution

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

eapytool-0.3.3-py3-none-any.whl (29.6 kB view details)

Uploaded Python 3

File details

Details for the file eapytool-0.3.3.tar.gz.

File metadata

  • Download URL: eapytool-0.3.3.tar.gz
  • Upload date:
  • Size: 35.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.8

File hashes

Hashes for eapytool-0.3.3.tar.gz
Algorithm Hash digest
SHA256 79672aced09b2e3de0399685ab36a38e44f9bb5ccc236a83ae7f7cd90ad6acc8
MD5 edc10c0298d52d7a42e5173aced144e2
BLAKE2b-256 e709a79a64cfb70b4750401fdc49f3a0fba97d051663186ae77b9a231a077c1a

See more details on using hashes here.

File details

Details for the file eapytool-0.3.3-py3-none-any.whl.

File metadata

  • Download URL: eapytool-0.3.3-py3-none-any.whl
  • Upload date:
  • Size: 29.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.8

File hashes

Hashes for eapytool-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2a3a3044013a46dc88f7f32efde8109b59b244f166bf69877a41591df5502ad0
MD5 a3de60928ee96ed4e39f50f0b28f8547
BLAKE2b-256 0d27cfe1115a5af37106c12235c34d4225704fce0e5005b6f087d6e7cd0e5ea3

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