Skip to main content

aiofiledol

aiofile (async filesys operations) with a simple (dict-like or list-like) interface

To install: pip install aiofiledol

Get the bytes contents of the file k.

>>> import os
>>> from aiofiledol import AioFileBytesReader
>>> filepath = __file__
>>> dirpath = os.path.dirname(__file__)  # path of the directory where I (the module file) am
>>> s = AioFileBytesReader(dirpath, max_levels=0)
>>>
>>> ####### Get the first 9 characters (as bytes) of this module #####################
>>> t = await s.aget(filepath)
>>> t[:14]
b'import asyncio'
>>>
>>> ####### Test key validation #####################
>>> await s.aget('not_a_valid_key')  # this key is not valid since not under the dirpath folder
Traceback (most recent call last):
    ...
filesys.KeyValidationError: 'Key not valid (usually because does not exist or access not permitted): not_a_valid_key'
>>>
>>> ####### Test further exceptions (that should be wrapped in KeyError) #####################
>>> # this key is valid, since under dirpath, but the file itself doesn't exist (hopefully for this test)
>>> non_existing_file = os.path.join(dirpath, 'non_existing_file')
>>> try:
...     await s.aget(non_existing_file)
... except KeyError:
...     print("KeyError (not FileNotFoundError) was raised.")
KeyError (not FileNotFoundError) was raised.

Set the contents of file k to be some bytes.

>>> from aiofiledol import AioFileBytesPersister
>>> from dol.filesys import mk_tmp_dol_dir
>>> import os
>>>
>>> rootdir = mk_tmp_dol_dir('test')
>>> rpath = lambda *p: os.path.join(rootdir, *p)
>>> s = AioFileBytesPersister(rootdir)
>>> k = rpath('foo')
>>> if k in s:
...     del s[k]  # delete key if present
...
>>> n = len(s)  # number of items in store
>>> await s.asetitem(k, b'bar')
>>> assert len(s) == n + 1  # there's one more item in store
>>> assert k in s
>>> assert (await s[k]) == b'bar'

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiofiledol-0.0.7.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

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

aiofiledol-0.0.7-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file aiofiledol-0.0.7.tar.gz.

File metadata

  • Download URL: aiofiledol-0.0.7.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for aiofiledol-0.0.7.tar.gz
Algorithm Hash digest
SHA256 4f11cff6507a46848c4de4c29f4cef533c9eb60e697ec6080c85aa15caaaedd5
MD5 3c9264a9d9431a140cad1aa00db36d3f
BLAKE2b-256 e07382e5159b6543fdd48d84f490650c94057b013c3f5194e9680bcf546a1b98

See more details on using hashes here.

File details

Details for the file aiofiledol-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: aiofiledol-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for aiofiledol-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 06e197ab1fa497417155a02d2d81639e2e85a585ba3c2b3356a5e750831c7183
MD5 796fa11db33d42ff07103baf18def682
BLAKE2b-256 86c2f8fe6be38fe9ef9182482b5ed9dafb9993469213307c40178b8c40720624

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.0.7 This release

2 files

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

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