📃 arrayfile
A file-backed numeric array using struct.pack. Does not support inserts or slicing.
Smaller than relying on numpy though.
▶️ Installation
pip install arrayfile
Usage
🗑 Temporary Array
This creates an array in your temp dir:
from arrayfile import Array
# Create a temporary array with float data
arr = Array('f')
arr.append(3.14)
arr.append(2.71)
arr.extend([1.41, 1.73])
print(f"Length: {len(arr)}")
print(f"Values: {[arr[i] for i in range(len(arr))]}")
arr.close() # Clean up resources
💽 Persistent Array
You can use the same file, if you want to persist your data across sessions:
from arrayfile import Array
# Create and populate an array file
arr = Array('i', 'numbers.array', 'w+b')
for i in range(1000):
arr.append(i * 2)
arr.close()
# Reopen the same file later
arr = Array('i', 'numbers.array', 'r+b')
print(f"Array has {len(arr)} elements")
print(f"First element: {arr[0]}")
print(f"Last element: {arr[-1]}")
# Add more data
arr.append(2000)
arr.close()
🔧 Context manager
It has a finalizer in case you forget to call close(), but if you like to keep
your code tidy, you can use a context manager, like so:
from arrayfile import Array
# Using double precision floats with context manager
with Array('d', 'measurements.array', 'w+b') as arr:
arr.extend([3.141592653589793, 2.718281828459045, 1.4142135623730951])
print(f"Stored {len(arr)} precise measurements")
for i, value in enumerate(arr):
print(f" {i}: {value:.15f}")
⚖️ License
WTFPL with one extra clause:
- Don't blame me.
Do what you like, but you're on your own.
🔗 Links
Metadata
Release files for arrayfile 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| arrayfile-0.1.0.tar.gz | 5.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| arrayfile-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.1 kB
Release files / arrayfile-0.1.0.tar.gz
| Download URL | arrayfile-0.1.0.tar.gz |
|---|---|
| Size | 5.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b8f2a45f5b44e55bb6e48b3280d9f067d26cdac60d0c6a9564471be3c83d80f7
|
|
BLAKE2b-256 checksum How to use checksums |
bf59e28512c4373e9ba5dea9503e739e5f928cf18618f48393ecac85c3f1315c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.21
|
Release files / arrayfile-0.1.0-py3-none-any.whl
| Download URL | arrayfile-0.1.0-py3-none-any.whl |
|---|---|
| Size | 5.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f0489ff3c4ddda986580501d9fa422b48e9fba44600aa3fa2cfacd3148639c16
|
|
BLAKE2b-256 checksum How to use checksums |
dc67e5899588e00416f121c616151048851a169aad43d4fe20e44575c13f0596
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.21
|