aiofile (async filesys operations) with a simple (dict-like or list-like) interface
Project description
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'
Project details
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.5.tar.gz
(10.3 kB
view details)
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 aiofiledol-0.0.5.tar.gz.
File metadata
- Download URL: aiofiledol-0.0.5.tar.gz
- Upload date:
- Size: 10.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a2c8ef76b8a861fe967bb79b05ed4e0382d36bae157746963233026c1f0fd530
|
|
| MD5 |
58420623258dc230b4f75c8dc130f7e2
|
|
| BLAKE2b-256 |
929baeb1596eb47f53e9cc1866b98fdedf18a6f139b572fe3478b9d3a1a91a43
|
File details
Details for the file aiofiledol-0.0.5-py3-none-any.whl.
File metadata
- Download URL: aiofiledol-0.0.5-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5e801105a0a8f24b45c31bc4e99e7180fa37d439a9b16a8ea9d473c3bec5b69a
|
|
| MD5 |
e0e8c1caf08a4e3376e20ec47aebb27d
|
|
| BLAKE2b-256 |
dbd690ed5747267d3b4eaf7a68517160454f9eee2bcf5a62f96a2e5a35c57954
|