focal


Namefocal JSON
Version 0.1.8 PyPI version JSON
download
home_pagehttps://github.com/i2mint/focal
SummaryData Access Objects for local files
upload_time2024-12-03 09:34:32
maintainerNone
docs_urlNone
authorNone
requires_pythonNone
licensemit
keywords data access file system data preparation storage orm
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# focal
Data Access Objects for local files.

# Examples

## quick store

```pydocstring
>>> 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

```pydocstring
>>> 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

```pydocstring
>>> 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.
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/i2mint/focal",
    "name": "focal",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "data access, file system, data preparation, storage, orm",
    "author": null,
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/2a/e5/740615cab969d92fa981def6b9633bc672e82e06b15fc819c325c54e3999/focal-0.1.8.tar.gz",
    "platform": "any",
    "description": "\n# focal\nData Access Objects for local files.\n\n# Examples\n\n## quick store\n\n```pydocstring\n>>> from py2store import QuickStore\n>>>\n>>> store = QuickStore()  # will print what (tmp) rootdir it is choosing\n>>> # Write something and then read it out again\n>>> store['foo'] = 'baz'\n>>> 'foo' in store  # do you have the key 'foo' in your store?\nTrue\n>>> store['foo']  # what is the value for 'foo'?\n'baz'\n>>>\n>>> # Okay, it behaves like a dict, but go have a look in your file system,  \n>>> # and see that there is now a file in the rootdir, named 'foo'!\n>>> \n>>> # Write something more complicated\n>>> store['hello/world'] = [1, 'flew', {'over': 'a', \"cuckoo's\": map}]\n>>> stored_val = store['hello/world']\n>>> stored_val == [1, 'flew', {'over': 'a', \"cuckoo's\": map}]  # was it retrieved correctly?\nTrue\n>>>\n>>> # how many items do you have now?\n>>> assert len(store) >= 2  # can't be sure there were no elements before, so can't assert == 2\n>>> \n>>> # delete the stuff you've written\n>>> del store['foo']\n>>> del store['hello/world']\n```\n\n## iterate over files\n\n```pydocstring\n>>> import os\n>>> filepath = __file__  # path to this module\n>>> dirpath = os.path.dirname(__file__)  # path of the directory where I (the module file) am\n>>> s = FileCollection(dirpath, max_levels=0)\n>>>\n>>> files_in_this_dir = list(s)\n>>> filepath in files_in_this_dir\nTrue\n```\n##  bytes contents of the file\n\n```pydocstring\n>>> import os\n>>> filepath = __file__\n>>> dirpath = os.path.dirname(__file__)  # path of the directory where I (the module file) am\n>>> s = FileBytesReader(dirpath, max_levels=0)\n>>>\n>>> ####### Get the first 9 characters (as bytes) of this module #####################\n>>> s[filepath][:9]\nb'import os'\n>>>\n>>> ####### Test key validation #####################\n>>> s['not_a_valid_key']  # this key is not valid since not under the dirpath folder\nTraceback (most recent call last):\n    ...\nfilesys.KeyValidationError: 'Key not valid (usually because does not exist or access not permitted): not_a_valid_key'\n>>>\n>>> ####### Test further exceptions (that should be wrapped in KeyError) #####################\n>>> # this key is valid, since under dirpath, but the file itself doesn't exist (hopefully for this test)\n>>> non_existing_file = os.path.join(dirpath, 'non_existing_file')\n>>> try:\n...     s[non_existing_file]\n... except KeyError:\n...     print(\"KeyError (not FileNotFoundError) was raised.\")\nKeyError (not FileNotFoundError) was raised.\n```\n",
    "bugtrack_url": null,
    "license": "mit",
    "summary": "Data Access Objects for local files",
    "version": "0.1.8",
    "project_urls": {
        "Homepage": "https://github.com/i2mint/focal"
    },
    "split_keywords": [
        "data access",
        " file system",
        " data preparation",
        " storage",
        " orm"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f2c011bd8031966e00d5621c947b1fde2ff1a9f08b81328499325b673fe1eae3",
                "md5": "2024608c576ad505729c59fa372e7beb",
                "sha256": "3e6e8b6fd5e7755227208268391f23682bfaa2ad08fc81a76fb36a31f9b2719d"
            },
            "downloads": -1,
            "filename": "focal-0.1.8-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2024608c576ad505729c59fa372e7beb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 20456,
            "upload_time": "2024-12-03T09:34:30",
            "upload_time_iso_8601": "2024-12-03T09:34:30.793330Z",
            "url": "https://files.pythonhosted.org/packages/f2/c0/11bd8031966e00d5621c947b1fde2ff1a9f08b81328499325b673fe1eae3/focal-0.1.8-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2ae5740615cab969d92fa981def6b9633bc672e82e06b15fc819c325c54e3999",
                "md5": "77954006a2b150b18ac7dbb31cfdaa1a",
                "sha256": "2f1c0aea18b04c17e61ee85bbee275e342953dd053119fe5b41c0e65732950ea"
            },
            "downloads": -1,
            "filename": "focal-0.1.8.tar.gz",
            "has_sig": false,
            "md5_digest": "77954006a2b150b18ac7dbb31cfdaa1a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 20681,
            "upload_time": "2024-12-03T09:34:32",
            "upload_time_iso_8601": "2024-12-03T09:34:32.184743Z",
            "url": "https://files.pythonhosted.org/packages/2a/e5/740615cab969d92fa981def6b9633bc672e82e06b15fc819c325c54e3999/focal-0.1.8.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-03 09:34:32",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "i2mint",
    "github_project": "focal",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "focal"
}
        
Elapsed time: 0.37090s