Arrays backed by disk
Project description
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}")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file arrayfile-0.0.1.tar.gz.
File metadata
- Download URL: arrayfile-0.0.1.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ba034a640aebbdb3e3dcaacb0c6dab7afa79a92e9c51ad1af16e24becc6fab6
|
|
| MD5 |
95168aacd0d6a9e64ab9b90855079a36
|
|
| BLAKE2b-256 |
a913061789042ca34eb05b020f9ab49ee9f08a36dbd71536d239c8fcfb0fab7b
|
File details
Details for the file arrayfile-0.0.1-py3-none-any.whl.
File metadata
- Download URL: arrayfile-0.0.1-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7fdf18623ba0bb7a695a098cd7969b1bcf6045fd2821b3c795e845a9b1e8a84b
|
|
| MD5 |
6b4f321a54f75bb0e0edcc9ae5009d57
|
|
| BLAKE2b-256 |
81a868a3359360f0ca22ceba4c4e28c411ed988c40881e446a6a38d226d16048
|