toolregistry.hub package¶
ToolRegistry Hub module providing commonly used tools.
This module serves as a central hub for various utility tools including: - Calculator: Basic arithmetic operations - FileSystem: File system operations - FileOps: File manipulation functions - UnitConverter: Unit conversion functions
Example
>>> from toolregistry.hub import Calculator, FileSystem, FileOps
>>> calc = Calculator()
>>> result = calc.add(1, 2)
>>> fs = FileSystem()
>>> exists = fs.exists('/path/to/file')
>>> ops = FileOps()
>>> ops.replace_lines('file.txt', 5, 'new content')
- class toolregistry.hub.Calculator[source]¶
Bases:
object
Performs mathematical calculations.
This class provides a unified interface for a wide range of mathematical operations, including basic arithmetic, scientific functions, statistical calculations, financial computations, random number generation, and expression evaluation.
- Constants()¶
pi, e, tau, inf, nan
- Basic arithmetic
add, subtract, multiply, divide, mod
- Power and roots
power, sqrt, cbrt, isqrt
- Distance and norm
dist, hypot
- Trigonometric functions
sin, cos, tan, asin, acos, atan, degrees, radians
- Hyperbolic functions
sinh, cosh, tanh, asinh, acosh, atanh
- Logarithmic and exponential functions
log, ln, log10, log2, log1p, exp, expm1
- Numerical processing
abs, round, floor, ceil, trunc, copysign, frexp, ldexp, modf, remainder, nextafter, ulp, fmod, isclose
- Combinatorics()¶
factorial, gcd, lcm, comb, perm
- Special functions
erf, erfc, gamma, lgamma
- Numerical validation
isfinite, isinf, isnan
- Statistical functions
average, median, mode, standard_deviation, min, max, sum, prod, fsum
- Financial calculations
simple_interest, compound_interest
- Random number generation
random, randint
- Expression evaluation
evaluate
- static dist(p: List[float], q: List[float]) float [source]¶
Calculates Euclidean distance between two points.
- static acosh(x: float) float [source]¶
Calculates the inverse hyperbolic cosine of x. x must be >= 1.
- static atanh(x: float) float [source]¶
Calculates the inverse hyperbolic tangent of x. |x| must be less than 1.
- static copysign(a: float, b: float) float [source]¶
Returns a float with the magnitude of a but the sign of b.
- static nextafter(x: float, y: float) float [source]¶
Returns next floating-point value after x towards y.
- static isclose(a: float, b: float, rel_tol: float = 1e-09, abs_tol: float = 0.0) bool [source]¶
Determines whether two floats are close in value.
- static perm(n: int, k: int) int [source]¶
Calculates the number of permutations of n items taken k at a time.
- static lgamma(x: float) float [source]¶
Calculates the natural logarithm of the absolute value of the Gamma function of x.
- static standard_deviation(numbers: List[float]) float [source]¶
Calculates population standard deviation of numbers.
- static fsum(numbers: List[float]) float [source]¶
Calculates an accurate floating point sum of numbers.
- static simple_interest(principal: float, rate: float, time: float) float [source]¶
Calculates simple interest.
- Parameters:
principal (float) – Initial amount
rate (float) – Annual interest rate (decimal)
time (float) – Time in years
- Returns:
Simple interest amount
- Return type:
float
- static compound_interest(principal: float, rate: float, time: float, periods: int = 1) float [source]¶
Calculates compound interest.
- Parameters:
principal (float) – Initial amount
rate (float) – Annual interest rate (decimal)
time (float) – Time in years
periods (int, optional) – Compounding periods per year. Defaults to 1.
- Returns:
Final amount after compounding
- Return type:
float
- static evaluate(expression: str) float | int | bool [source]¶
Evaluates a mathematical expression using a unified interface.
This method is intended for complex expressions that combine two or more operations. For simple, single-step operations, please directly use the corresponding static method (e.g., add, subtract).
- The evaluate method supports the following operations:
Constants: pi, e, tau, inf, nan
Basic arithmetic: add, subtract, multiply, divide, mod
Power and roots: power, sqrt, cbrt, isqrt
Distance and norm: dist, hypot
Trigonometric functions: sin, cos, tan, asin, acos, atan, degrees, radians
Hyperbolic functions: sinh, cosh, tanh, asinh, acosh, atanh
Logarithmic and exponential functions: log, ln, log10, log2, log1p, exp, expm1
Numerical processing: abs, round, floor, ceil, trunc, copysign, frexp, ldexp, modf, remainder, nextafter, ulp, fmod, isclose
Combinatorics: factorial, gcd, lcm, comb, perm
Special functions: erf, erfc, gamma, lgamma
Numerical validation: isfinite, isinf, isnan
Statistical functions: average, median, mode, standard_deviation, min, max, sum, prod, fsum
Financial calculations: simple_interest, compound_interest
Random number generation: random, randint
The expression should be a valid Python expression utilizing the above functions. For example: “add(2, 3) * power(2, 3) + sqrt(16)”.
- Parameters:
expression (str) – Mathematical expression to evaluate.
- Returns:
The result of the evaluated expression.
- Return type:
Union[float, int, bool]
- Raises:
ValueError – If the expression is invalid or its evaluation fails.
- class toolregistry.hub.FileSystem[source]¶
Bases:
object
Provides file system operations related to structure, state, and metadata.
- static exists(path: str) bool [source]¶
Checks if a path exists.
- Parameters:
path – The path string to check.
- Returns:
True if path exists, False otherwise
- static is_file(path: str) bool [source]¶
Checks if a path points to a file.
- Parameters:
path – The path string to check.
- Returns:
True if the path points to a file, False otherwise.
- static is_dir(path: str) bool [source]¶
Checks if a path points to a directory.
- Parameters:
path – The path string to check.
- Returns:
True if the path points to a directory, False otherwise.
- static list_dir(path: str, depth: int = 1, show_hidden: bool = False) List[str] [source]¶
Lists contents of a directory up to a specified depth.
- Parameters:
path – The directory path string to list.
depth – Maximum depth to list (default=1). Must be >= 1.
show_hidden – If False, filters out hidden files/directories. On Unix-like systems (Linux, macOS), this means names starting with ‘.’. On Windows, this means files/directories with the ‘hidden’ attribute set, as well as names starting with ‘.’. (default is False).
- Returns:
List of relative path strings of items in the directory up to the specified depth.
- Raises:
ValueError – If depth is less than 1.
FileNotFoundError – If the path does not exist or is not a directory.
- static create_file(path: str) None [source]¶
Creates an empty file or updates the timestamp if it already exists (like ‘touch’).
- Parameters:
path – The file path string to create or update.
- static copy(src: str, dst: str) None [source]¶
Copies a file or directory.
- Parameters:
src – Source path string.
dst – Destination path string.
- static move(src: str, dst: str) None [source]¶
Moves/renames a file or directory.
- Parameters:
src – Source path string.
dst – Destination path string.
- static delete(path: str) None [source]¶
Deletes a file or directory recursively.
- Parameters:
path – Path string to delete.
- static get_size(path: str) int [source]¶
Gets file/directory size in bytes (recursive for directories).
- Parameters:
path – Path string to check size of.
- Returns:
Size in bytes.
- Raises:
FileNotFoundError – If the path does not exist.
- static get_last_modified_time(path: str) float [source]¶
Gets the last modified time of a file or directory.
- Parameters:
path – Path string to the file or directory.
- Returns:
Last modified time as a Unix timestamp (float).
- Raises:
FileNotFoundError – If the path does not exist.
- static join_paths(*paths: str) str [source]¶
Joins multiple path components into a normalized string path.
- Parameters:
*paths – One or more path component strings.
- Returns:
Joined and normalized path string.
- static get_absolute_path(path: str) str [source]¶
Gets the absolute path as a normalized string.
- Parameters:
path – Path string to convert.
- Returns:
Absolute path string.
- static create_dir(path: str, parents: bool = True, exist_ok: bool = True) None [source]¶
Creates a directory, including parent directories if needed (defaults to True).
- Parameters:
path – Directory path string to create.
parents – Create parent directories if needed (default=True).
exist_ok – Don’t raise error if directory exists (default=True).
- class toolregistry.hub.FileOps[source]¶
Bases:
object
Core file operations toolkit designed for LLM agent integration.
Handles file reading, atomic writing, appending, searching, and diff-based modifications.
- static replace_by_diff(path: str, diff: str) None [source]¶
Apply unified diff format changes atomically to a file.
- Parameters:
path – The file path to modify.
diff – Unified diff text (must use standard format with —/+++ headers and @@ hunk markers).
- Example diff text:
— a/original_file +++ b/modified_file @@ -1,3 +1,3 @@ -line2 +line2 modified
- Raises:
ValueError – On invalid diff format or patch failure
- static search_files(path: str, regex: str, file_pattern: str = '*') List[dict] [source]¶
Perform regex search across files in a directory, returning matches with context.
- Parameters:
path – The directory path to search recursively.
regex – The regex pattern to search for.
file_pattern – Glob pattern to filter files (default=’*’).
- Returns:
file: file path
line_num: line number of match (1-based)
line: matched line content
context: list of context lines (tuples of line_num, line content)
- Return type:
List of dicts with keys
- static replace_by_git(path: str, diff: str) None [source]¶
Apply git conflict style diff atomically to a file, replacing conflicted sections.
- Parameters:
path – File path to modify.
diff – Git conflict style diff text (using <<<<<<< SEARCH, =======, >>>>>>> REPLACE markers).
- Example diff text:
<<<<<<< SEARCH line2 ======= line2 modified >>>>>>> REPLACE
- Raises:
ValueError – On invalid diff format or patch failure
- static read_file(path: str) str [source]¶
Read text file content.
- Parameters:
path – File path to read
- Returns:
File content as string
- Raises:
FileNotFoundError – If path doesn’t exist
UnicodeError – On encoding failures
- static write_file(path: str, content: str) None [source]¶
Atomically write content to a text file (overwrite). Creates the file if it doesn’t exist.
- Parameters:
path – Destination file path
content – Content to write
- static append_file(path: str, content: str) None [source]¶
Append content to a text file. Creates the file if it doesn’t exist.
- Parameters:
path – Destination file path
content – Content to append
- static make_diff(ours: str, theirs: str) str [source]¶
Generate unified diff text between two strings.
- Parameters:
ours – The ‘ours’ version string.
theirs – The ‘theirs’ version string.
Note
Intended for comparison/visualization, not direct modification. not for direct text modification tasks.
- Returns:
Unified diff text
- static make_git_conflict(ours: str, theirs: str) str [source]¶
Generate git merge conflict marker text between two strings.
- Parameters:
ours – The ‘ours’ version string.
theirs – The ‘theirs’ version string.
Note
Intended for comparison/visualization, not direct modification. not for direct text modification tasks.
- Returns:
Text with conflict markers
- class toolregistry.hub.UnitConverter[source]¶
Bases:
object
Performs unit conversions.
- Temperature conversions
celsius_to_fahrenheit, fahrenheit_to_celsius, kelvin_to_celsius, celsius_to_kelvin
- Length conversions
meters_to_feet, feet_to_meters, centimeters_to_inches, inches_to_centimeters
- Weight conversions
kilograms_to_pounds, pounds_to_kilograms
- Time conversions
seconds_to_minutes, minutes_to_seconds
- Capacity conversions
liters_to_gallons, gallons_to_liters
- Area conversions
square_meters_to_square_feet, square_feet_to_square_meters
- Speed conversions
kmh_to_mph, mph_to_kmh
- Data storage conversions
bits_to_bytes, bytes_to_kilobytes, kilobytes_to_megabytes
- Pressure conversions
pascal_to_bar, bar_to_atm
- Power conversions
watts_to_kilowatts, kilowatts_to_horsepower
- Energy conversions
joules_to_calories, calories_to_kilowatt_hours
- Frequency conversions
hertz_to_kilohertz, kilohertz_to_megahertz
- Fuel economy conversions
km_per_liter_to_mpg, mpg_to_km_per_liter
- Electrical conversions
ampere_to_milliampere, volt_to_kilovolt, ohm_to_kiloohm
- Magnetic conversions
weber_to_tesla, gauss_to_tesla
- Radiation conversions
gray_to_sievert
- Light intensity conversions
lux_to_lumen, lumen_to_lux
- static square_meters_to_square_feet(sqm: float) float [source]¶
Convert square meters to square feet.
- static square_feet_to_square_meters(sqft: float) float [source]¶
Convert square feet to square meters.
- static calories_to_kilowatt_hours(calories: float) float [source]¶
Convert calories to kilowatt hours.
- static km_per_liter_to_mpg(kmpl: float) float [source]¶
Convert kilometers per liter to miles per gallon.
- static mpg_to_km_per_liter(mpg: float) float [source]¶
Convert miles per gallon to kilometers per liter.
- static weber_to_tesla(weber: float, area: float = 1.0) float [source]¶
Convert magnetic flux (weber) to magnetic flux density (tesla). Assumes a default area of 1 square meter if not specified.
- static tesla_to_weber(tesla: float, area: float = 1.0) float [source]¶
Convert magnetic flux density (tesla) to magnetic flux (weber). Assumes a default area of 1 square meter if not specified.
Submodules¶
- toolregistry.hub.calculator module
Calculator
Calculator.Constants()
Calculator.Combinatorics()
Calculator.pi()
Calculator.e()
Calculator.tau()
Calculator.inf()
Calculator.nan()
Calculator.add()
Calculator.subtract()
Calculator.multiply()
Calculator.divide()
Calculator.mod()
Calculator.power()
Calculator.sqrt()
Calculator.cbrt()
Calculator.isqrt()
Calculator.dist()
Calculator.hypot()
Calculator.sin()
Calculator.cos()
Calculator.tan()
Calculator.asin()
Calculator.acos()
Calculator.atan()
Calculator.degrees()
Calculator.radians()
Calculator.sinh()
Calculator.cosh()
Calculator.tanh()
Calculator.asinh()
Calculator.acosh()
Calculator.atanh()
Calculator.log()
Calculator.ln()
Calculator.log10()
Calculator.log2()
Calculator.log1p()
Calculator.exp()
Calculator.expm1()
Calculator.abs()
Calculator.round()
Calculator.floor()
Calculator.ceil()
Calculator.trunc()
Calculator.copysign()
Calculator.frexp()
Calculator.ldexp()
Calculator.modf()
Calculator.remainder()
Calculator.nextafter()
Calculator.ulp()
Calculator.fmod()
Calculator.isclose()
Calculator.factorial()
Calculator.gcd()
Calculator.lcm()
Calculator.comb()
Calculator.perm()
Calculator.erf()
Calculator.erfc()
Calculator.gamma()
Calculator.lgamma()
Calculator.isfinite()
Calculator.isinf()
Calculator.isnan()
Calculator.average()
Calculator.median()
Calculator.mode()
Calculator.standard_deviation()
Calculator.min()
Calculator.max()
Calculator.sum()
Calculator.prod()
Calculator.fsum()
Calculator.simple_interest()
Calculator.compound_interest()
Calculator.random()
Calculator.randint()
Calculator.evaluate()
- toolregistry.hub.file_ops module
- toolregistry.hub.filesystem module
FileSystem
FileSystem.exists()
FileSystem.is_file()
FileSystem.is_dir()
FileSystem.list_dir()
FileSystem.create_file()
FileSystem.copy()
FileSystem.move()
FileSystem.delete()
FileSystem.get_size()
FileSystem.get_last_modified_time()
FileSystem.join_paths()
FileSystem.get_absolute_path()
FileSystem.create_dir()
FileSystem.exists()
FileSystem.is_file()
FileSystem.is_dir()
FileSystem.list_dir()
FileSystem.create_file()
FileSystem.copy()
FileSystem.move()
FileSystem.delete()
FileSystem.get_size()
FileSystem.get_last_modified_time()
FileSystem.join_paths()
FileSystem.get_absolute_path()
FileSystem.create_dir()
- toolregistry.hub.unit_converter module
UnitConverter
UnitConverter.celsius_to_fahrenheit()
UnitConverter.fahrenheit_to_celsius()
UnitConverter.kelvin_to_celsius()
UnitConverter.celsius_to_kelvin()
UnitConverter.meters_to_feet()
UnitConverter.feet_to_meters()
UnitConverter.centimeters_to_inches()
UnitConverter.inches_to_centimeters()
UnitConverter.kilograms_to_pounds()
UnitConverter.pounds_to_kilograms()
UnitConverter.seconds_to_minutes()
UnitConverter.minutes_to_seconds()
UnitConverter.liters_to_gallons()
UnitConverter.gallons_to_liters()
UnitConverter.square_meters_to_square_feet()
UnitConverter.square_feet_to_square_meters()
UnitConverter.kmh_to_mph()
UnitConverter.mph_to_kmh()
UnitConverter.bits_to_bytes()
UnitConverter.bytes_to_kilobytes()
UnitConverter.kilobytes_to_megabytes()
UnitConverter.pascal_to_bar()
UnitConverter.bar_to_atm()
UnitConverter.watts_to_kilowatts()
UnitConverter.kilowatts_to_horsepower()
UnitConverter.joules_to_calories()
UnitConverter.calories_to_kilowatt_hours()
UnitConverter.hertz_to_kilohertz()
UnitConverter.kilohertz_to_megahertz()
UnitConverter.km_per_liter_to_mpg()
UnitConverter.mpg_to_km_per_liter()
UnitConverter.ampere_to_milliampere()
UnitConverter.volt_to_kilovolt()
UnitConverter.ohm_to_kiloohm()
UnitConverter.weber_to_tesla()
UnitConverter.gauss_to_tesla()
UnitConverter.tesla_to_weber()
UnitConverter.tesla_to_gauss()
UnitConverter.gray_to_sievert()
UnitConverter.lux_to_lumen()
UnitConverter.lumen_to_lux()