Data Access Objects for local files
Project description
focal
Data Access Objects for local files.
Examples
quick store
>>> from py2store import QuickStore
>>>
>>> store = QuickStore() # will print what (tmp) rootdir it is choosing
>>> # Write something and then read it out again
>>> store['foo'] = 'baz'
>>> 'foo' in store # do you have the key 'foo' in your store?
True
>>> store['foo'] # what is the value for 'foo'?
'baz'
>>>
>>> # Okay, it behaves like a dict, but go have a look in your file system,
>>> # and see that there is now a file in the rootdir, named 'foo'!
>>>
>>> # Write something more complicated
>>> store['hello/world'] = [1, 'flew', {'over': 'a', "cuckoo's": map}]
>>> stored_val = store['hello/world']
>>> stored_val == [1, 'flew', {'over': 'a', "cuckoo's": map}] # was it retrieved correctly?
True
>>>
>>> # how many items do you have now?
>>> assert len(store) >= 2 # can't be sure there were no elements before, so can't assert == 2
>>>
>>> # delete the stuff you've written
>>> del store['foo']
>>> del store['hello/world']
iterate over files
>>> import os
>>> filepath = __file__ # path to this module
>>> dirpath = os.path.dirname(__file__) # path of the directory where I (the module file) am
>>> s = FileCollection(dirpath, max_levels=0)
>>>
>>> files_in_this_dir = list(s)
>>> filepath in files_in_this_dir
True
bytes contents of the file
>>> import os
>>> filepath = __file__
>>> dirpath = os.path.dirname(__file__) # path of the directory where I (the module file) am
>>> s = FileBytesReader(dirpath, max_levels=0)
>>>
>>> ####### Get the first 9 characters (as bytes) of this module #####################
>>> s[filepath][:9]
b'import os'
>>>
>>> ####### Test key validation #####################
>>> s['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:
... s[non_existing_file]
... except KeyError:
... print("KeyError (not FileNotFoundError) was raised.")
KeyError (not FileNotFoundError) was raised.
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
focal-0.1.10.tar.gz
(23.2 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
focal-0.1.10-py3-none-any.whl
(20.4 kB
view details)
File details
Details for the file focal-0.1.10.tar.gz.
File metadata
- Download URL: focal-0.1.10.tar.gz
- Upload date:
- Size: 23.2 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 |
e2feeaa67112ea866631d5047fae006596b29b820f3985ed30ba62f557529360
|
|
| MD5 |
764ddf1167a67c539bb7d5ca78fd9f4c
|
|
| BLAKE2b-256 |
2f51b7b73990e95b9c297385526d4a91402a834bca4da4ce2646d4a56407e863
|
File details
Details for the file focal-0.1.10-py3-none-any.whl.
File metadata
- Download URL: focal-0.1.10-py3-none-any.whl
- Upload date:
- Size: 20.4 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 |
a64e03d48ee7bb0a40fb8ae98923cafd45c0b92c3d45a151bb6ba02c2e41227c
|
|
| MD5 |
f8d32c9cbe904f2d5b6bcf5f0448eb2b
|
|
| BLAKE2b-256 |
417f6092cb800bbe452dbf30b0b7f1efbc55e75ef685e99c2bcf72ca079d1eac
|