Skip to main content

Expressive array utilities with an optional C backend.

Project description

smartarr

smartarr is an expressive array utility layer for Python with a clean smart(arr) API and an optional C backend for fast core operations.

Why it exists

The goal is simple:

  • one readable interface for lists, tuples, and NumPy arrays
  • fast common operations when the C extension is available
  • chainable transformations that still feel like Python
from smartarr import smart

value = smart([1, 2, 3, 4, 5]).rotate(2).reverse().middle()
print(value)  # 1

Install

Local install from this project:

python -m pip install .

Editable install for development:

python -m pip install -e .

Optional NumPy support:

python -m pip install ".[numpy]"

If a compiler is available, smartarr builds its C extension automatically. If not, installation still succeeds and falls back to the pure Python backend.

Quick start

from smartarr import smart

arr = smart([1, 2, 3, 4])

print(arr.first())                 # 1
print(arr.last())                  # 4
print(arr.middle())                # 3
print(arr.middle(mode="left"))     # 2
print(arr.middle(mode="avg"))      # 2.5
print(arr.rotate(1).to_list())     # [4, 1, 2, 3]
print(arr.reverse().to_list())     # [4, 3, 2, 1]
print(arr.chunk(2).to_list())      # [[1, 2], [3, 4]]
print(arr.window(2).to_list())     # [[1, 2], [2, 3], [3, 4]]

Design notes

  • middle() defaults to the right-middle element for even-length arrays, matching arr[len(arr) // 2].
  • Structural methods return a new SmartArray, so chaining works naturally.
  • Terminal methods return a final value, such as an element, a number, or a dictionary.
  • Flat transformations preserve the original adapter where practical. Shape-changing operations return list-shaped data by default.

Supported input types

  • list
  • tuple
  • NumPy ndarray when NumPy is installed
  • general iterables such as range

Current feature coverage

V1

  • first
  • last
  • middle
  • rotate
  • reverse
  • len
  • is_empty

V2

  • chunk
  • window
  • random
  • find
  • count
  • contains
  • is_sorted
  • sorted

V3

  • map
  • filter
  • reduce
  • sum
  • mean
  • median
  • min
  • max
  • peaks
  • unique
  • duplicates
  • frequency
  • flatten
  • reshape

Development

Run tests:

python -m unittest discover -s tests -v

License

MIT

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

smartarr-0.1.0.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

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

smartarr-0.1.0-cp311-cp311-win_amd64.whl (18.3 kB view details)

Uploaded CPython 3.11Windows x86-64

File details

Details for the file smartarr-0.1.0.tar.gz.

File metadata

  • Download URL: smartarr-0.1.0.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.12

File hashes

Hashes for smartarr-0.1.0.tar.gz
Algorithm Hash digest
SHA256 09be8331b5636c3c3c33456f0de64b44254864450f4e025b949cda6126885649
MD5 ff26aa9399ea04bae446c75f72df0a8e
BLAKE2b-256 d58331970e11fb3e2044d9c646c0e64fb0afb1139025bcc1fef33570ca01eb74

See more details on using hashes here.

File details

Details for the file smartarr-0.1.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: smartarr-0.1.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 18.3 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.12

File hashes

Hashes for smartarr-0.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 0afb0404668b49be59148c000b1bc15401c2d1178e7c9b8476176e9b7256b087
MD5 0b1573a8619669a3ed550e2dd4463a96
BLAKE2b-256 24260c8498c6f44b2562f704c2008b78c28108b91d1859b8a9afb7cc1ff9c34f

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