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'
Metadata
Release files for aiofiledol 0.0.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| aiofiledol-0.0.9.tar.gz | 13.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aiofiledol-0.0.9-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 23.6 kB
Release files / aiofiledol-0.0.9.tar.gz
| Download URL | aiofiledol-0.0.9.tar.gz |
|---|---|
| Size | 13.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cb4955c508c58d37ef7e298578e2e09ecb0ff0739098db445f732cbbbfee02a9
|
|
BLAKE2b-256 checksum How to use checksums |
0036084db3aed8a378364b7d1a808b542dbd953f571b04fd99ff5d1031ad4f89
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.17 {"installer":{"name":"uv","version":"0.12.17","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}
|
Release files / aiofiledol-0.0.9-py3-none-any.whl
| Download URL | aiofiledol-0.0.9-py3-none-any.whl |
|---|---|
| Size | 10.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
46f736b02520d8da7e0312d9a2a1c0018ab5eeda7157d269cdf645c79c8ff9a1
|
|
BLAKE2b-256 checksum How to use checksums |
da6e2c0264ba566a22af5d70a8a9bc921d925430d596fd5f484ce1da28c42e2e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.17 {"installer":{"name":"uv","version":"0.12.17","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}
|