Skip to main content

pyarrlib

A small Python utility library for working with arrays, nested array structures, and dictionaries.

This project provides helper functions for reversing arrays, computing numeric aggregates, counting nested leaves, splitting arrays, solving small systems of linear equations, and working with dictionary keys and values.

Features

Array Functions

  • reverse_arr(array) — reverse a one-dimensional sequence
  • sum_arr(array) — compute the sum of numeric values
  • multiplication_arr(array) — compute the product of numeric values
  • min(array) — find the smallest numeric value in a sequence
  • max(array) — find the largest numeric value in a sequence
  • arifmetic_mean(array) — compute the arithmetic mean of numeric values
  • sort(array) — sort the array in-place
  • same(array1, array2) — find common elements between two arrays
  • step_filter(array, step, first_num=0) — filter array with step
  • type_filter(array, type_filt) — filter elements by type
  • range_arr(array, first, last) — get numeric values inside an inclusive range
  • range_other(array, first, last) — get numeric values outside an inclusive range
  • chunk(array, size) — split the array into fixed-size chunks
  • mv(array, i1, i2) — move element from index i1 to i2
  • hw_times(array, key) — count occurrences of key
  • not_same(array, array2) — find elements not common between arrays
  • section(array, part) — split the array into consecutive sections

Nested Array Functions

  • leafs(array) — flatten nested integer arrays
  • num_of_leafs(array) — count integer leaf nodes in nested arrays
  • len_arr(array) — count all scalar leaves in nested arrays
  • equation_system(full_matrix) — solve 2×2 or 3×3 linear systems using determinants

Dictionary Functions

  • dict_max(d) — find the maximum value in dictionary values
  • dict_min(d) — find the minimum value in dictionary values
  • is_key_value_in_dict(d, key, value) — check if key-value pair exists
  • key_sum(d) — sum numeric keys in dictionary
  • key_multiplication(d) — multiply numeric keys in dictionary
  • same_keys(d1, d2) — find common keys between dictionaries
  • same_values(d1, d2) — find common values between dictionaries
  • value_sum(d) — sum numeric values in dictionary
  • value_multiplication(d) — multiply numeric values in dictionary

Installation

From the repository root, install in editable mode:

python -m pip install -e .

If you prefer not to install, you can run code directly from this project by ensuring the repository root is on PYTHONPATH.

Usage

from pyarrlib import (
    ArrayTypeError,
    IsNotArrayError,
    arifmetic_mean,
    chunk,
    dict_max,
    dict_min,
    equation_system,
    hw_times,
    is_key_value_in_dict,
    key_sum,
    key_multiplication,
    leafs,
    len_arr,
    max,
    min,
    multiplication_arr,
    mv,
    not_same,
    num_of_leafs,
    range_arr,
    reverse_arr,
    same,
    section,
    sort,
    step_filter,
    sum_arr,
    type_filter,
    value_sum,
    value_multiplication,
)

print(reverse_arr([1, 'hello', 3, True]))
# [True, 3, 'hello', 1]

print(sum_arr([1, 5, 4, 3, 8]))
# 21

print(multiplication_arr([4, 1, 2, 5, 7]))
# 280

print(min([1, 3, 6, -3, 2]))
# -3

print(arifmetic_mean([2, 4, 6]))
# 4.0

nested = [[1, 2, [3]], [4, [5, 6]]]
print(leafs(nested))
# [1, 2, 3, 4, 5, 6]
print(num_of_leafs(nested))
# 6
print(len_arr(nested))
# 6

system = [
    [2, -1, 1],
    [1, 1, 1],
    [1, 2, -1],
]
print(equation_system([row + [value] for row, value in zip(system, [1, 2, 3])]))

arr = [1, 2, 3, 4, 5]
sort(arr)
print(arr)  # [1, 2, 3, 4, 5]

print(chunk([1, 2], 3))  # [[1, 2, 3]]

print(hw_times([1, 2, 2, 3], 2))  # 2

print(type_filter([1, 'a', 2.0, True], int))  # [1, True]

d = {'a': 1, 'b': 2}
print(key_sum(d))  # 0
print(value_sum(d))  # 3
print(is_key_value_in_dict(d, 'a', 1))  # True

API Reference

Exceptions

  • ArrayTypeError — raised when array contains unsupported element types for numeric operations
  • IsNotArrayError — raised when input is not an array-like structure

Array Functions

  • reverse_arr(array) — Return a new sequence with the elements in reverse order.
  • sum_arr(array) — Return the sum of numeric values in the array. Returns ArrayTypeError if non-numeric elements are present.
  • multiplication_arr(array) — Return the product of numeric values in the array. Returns ArrayTypeError if non-numeric elements are present.
  • min(array) — Return the smallest numeric value from a one-dimensional sequence. Raises ArrayTypeError for non-numeric elements.
  • max(array) — Return the largest numeric value from a one-dimensional sequence. Raises ArrayTypeError for non-numeric elements.
  • arifmetic_mean(array) — Return the arithmetic mean of numeric values in the array.
  • sort(array) — Sort the array in-place and return the sorted array.
  • same(array1, array2) — Return common elements between two arrays.
  • step_filter(array, step, first_num=0) — Return sliced array with the given step.
  • type_filter(array, type_filt) — Return elements matching the specified type.
  • range_arr(array, first, last) — Return numeric elements inside the inclusive range [first, last].
  • range_other(array, first, last) — Return numeric elements outside the inclusive range [first, last].
  • chunk(array, size) — Split the array into consecutive chunks of size size.
  • mv(array, i1, i2) — Move an element from index i1 to i2 in-place.
  • hw_times(array, key) — Count occurrences of key in the array.
  • not_same(array, array2) — Return elements that are not common between the two arrays.
  • section(array, part) — Split the array into consecutive sections of length part.

Nested Array Functions

  • leafs(array) — Return a flat list containing all integer leaf values from a nested array structure.
  • num_of_leafs(array) — Count integer leaf nodes recursively in a nested array structure.
  • len_arr(array) — Count all scalar leaf values in a nested array structure. Supported scalar types include int, str, float, and bool.
  • equation_system(full_matrix) — Solve a 2×2 or 3×3 system of linear equations supplied as an augmented matrix.

Dictionary Functions

  • dict_max(d) — Return the maximum value from dictionary values.
  • dict_min(d) — Return the minimum value from dictionary values.
  • is_key_value_in_dict(d, key, value) — Return True if the key-value pair exists in the dictionary.
  • key_sum(d) — Return the sum of numeric dictionary keys.
  • key_multiplication(d) — Return the product of numeric dictionary keys.
  • same_keys(d1, d2) — Return a list of common keys between two dictionaries.
  • same_values(d1, d2) — Return a list of common values between two dictionaries.
  • value_sum(d) — Return the sum of numeric dictionary values.
  • value_multiplication(d) — Return the product of numeric dictionary values.

Running the included checks

The repository includes a simple assertion-based test file.

python tests/test.py

Project structure

  • setup.py — package metadata and build configuration
  • README.md — project documentation
  • src/pyarrlib/__init__.py — package initialization
  • src/pyarrlib/sync_arrpy.py — synchronous array utility functions
  • src/pyarrlib/sync_multidim_arr.py — synchronous nested array traversal functions
  • src/pyarrlib/sync_dict.py — synchronous dictionary utility functions
  • src/pyarrlib/sync__checks.py — validation helpers and exception classes
  • src/pyarrlib/async_arrpy.py — asynchronous array utility functions
  • src/pyarrlib/async_multidim_arr.py — asynchronous nested array traversal functions
  • src/pyarrlib/async_dict.py — asynchronous dictionary utility functions
  • src/pyarrlib/async__checks.py — asynchronous validation helpers and exception classes
  • tests/test.py — example assertions covering core behavior

License

This project is licensed under MIT.

Metadata

Release files for pyarrlib 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyarrlib 1.0.0
File Size Uploaded Provenance
pyarrlib-1.0.0.tar.gz 10.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pyarrlib 1.0.0
File Interpreter ABI Platform
pyarrlib-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 20.5 kB

Release files / pyarrlib-1.0.0.tar.gz

Download URL pyarrlib-1.0.0.tar.gz
Size 10.3 kB
Tags Source
SHA-256 checksum
How to use checksums
996480254e8ad8f8203447971bbb6308324d6eeb6834e7443f6333ff3c70dd91
BLAKE2b-256 checksum
How to use checksums
ab9425cdd914df32070003247ae62adedad69312af6948e96853e658a9af75c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.15.0a5

Release files / pyarrlib-1.0.0-py3-none-any.whl

Download URL pyarrlib-1.0.0-py3-none-any.whl
Size 10.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b5998df91768fecf9a3870b4d1f7c2cb674316acfe28f96d58d5bc5e7cdfb141
BLAKE2b-256 checksum
How to use checksums
161eb0317d43c2cf6b5665254797b70ababe831fe0544e0518dcc9eeee2305e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.15.0a5

Security for pyarrlib 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page