# arrayfile
A file-backed numeric array using struct.pack. Does not support inserts or
slicing.
Smaller than relying on numpy though.
## Installation
```bash
pip install arrayfile
```
## Usage
### Temporary Array
This creates an array in your temp dir:
```python
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:
```python
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:
```python
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}")
```
Raw data
{
"_id": null,
"home_page": null,
"name": "arrayfile",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "logging, terminal, scrollback, indexing",
"author": null,
"author_email": "Gareth Davidson <gaz@bitplane.net>",
"download_url": "https://files.pythonhosted.org/packages/a9/13/061789042ca34eb05b020f9ab49ee9f08a36dbd71536d239c8fcfb0fab7b/arrayfile-0.0.1.tar.gz",
"platform": null,
"description": "# arrayfile\n\nA file-backed numeric array using struct.pack. Does not support inserts or\nslicing.\n\nSmaller than relying on numpy though.\n\n## Installation\n\n```bash\npip install arrayfile\n```\n\n## Usage\n\n### Temporary Array\n\nThis creates an array in your temp dir:\n\n```python\nfrom arrayfile import Array\n\n# Create a temporary array with float data\narr = Array('f')\narr.append(3.14)\narr.append(2.71)\narr.extend([1.41, 1.73])\n\nprint(f\"Length: {len(arr)}\")\nprint(f\"Values: {[arr[i] for i in range(len(arr))]}\")\narr.close() # Clean up resources\n```\n\n### Persistent Array\n\nYou can use the same file, if you want to persist your data across sessions:\n\n```python\nfrom arrayfile import Array\n\n# Create and populate an array file\narr = Array('i', 'numbers.array', 'w+b')\nfor i in range(1000):\n arr.append(i * 2)\narr.close()\n\n# Reopen the same file later\narr = Array('i', 'numbers.array', 'r+b')\nprint(f\"Array has {len(arr)} elements\")\nprint(f\"First element: {arr[0]}\")\nprint(f\"Last element: {arr[-1]}\")\n\n# Add more data\narr.append(2000)\narr.close()\n```\n\n## Context manager\n\nIt has a finalizer in case you forget to call `close()`, but if you like to keep\nyour code tidy, you can use a context manager, like so:\n\n```python\nfrom arrayfile import Array\n\n# Using double precision floats with context manager\nwith Array('d', 'measurements.array', 'w+b') as arr:\n arr.extend([3.141592653589793, 2.718281828459045, 1.4142135623730951])\n\n print(f\"Stored {len(arr)} precise measurements\")\n for i, value in enumerate(arr):\n print(f\" {i}: {value:.15f}\")\n```\n\n\n",
"bugtrack_url": null,
"license": null,
"summary": "Arrays backed by disk",
"version": "0.0.1",
"project_urls": null,
"split_keywords": [
"logging",
" terminal",
" scrollback",
" indexing"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "81a868a3359360f0ca22ceba4c4e28c411ed988c40881e446a6a38d226d16048",
"md5": "6b4f321a54f75bb0e0edcc9ae5009d57",
"sha256": "7fdf18623ba0bb7a695a098cd7969b1bcf6045fd2821b3c795e845a9b1e8a84b"
},
"downloads": -1,
"filename": "arrayfile-0.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "6b4f321a54f75bb0e0edcc9ae5009d57",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 5229,
"upload_time": "2025-07-19T02:22:19",
"upload_time_iso_8601": "2025-07-19T02:22:19.956583Z",
"url": "https://files.pythonhosted.org/packages/81/a8/68a3359360f0ca22ceba4c4e28c411ed988c40881e446a6a38d226d16048/arrayfile-0.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "a913061789042ca34eb05b020f9ab49ee9f08a36dbd71536d239c8fcfb0fab7b",
"md5": "95168aacd0d6a9e64ab9b90855079a36",
"sha256": "9ba034a640aebbdb3e3dcaacb0c6dab7afa79a92e9c51ad1af16e24becc6fab6"
},
"downloads": -1,
"filename": "arrayfile-0.0.1.tar.gz",
"has_sig": false,
"md5_digest": "95168aacd0d6a9e64ab9b90855079a36",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 4717,
"upload_time": "2025-07-19T02:22:21",
"upload_time_iso_8601": "2025-07-19T02:22:21.282541Z",
"url": "https://files.pythonhosted.org/packages/a9/13/061789042ca34eb05b020f9ab49ee9f08a36dbd71536d239c8fcfb0fab7b/arrayfile-0.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-19 02:22:21",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "arrayfile"
}