peridata


Nameperidata JSON
Version 1.1.0 PyPI version JSON
download
home_pageNone
SummaryA tiny dictionary-like file storage system.
upload_time2024-10-09 07:57:34
maintainerNone
docs_urlNone
authorNone
requires_pythonNone
licenseMIT
keywords storage
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # peridata

peridata is a simple, tiny (<4KB!) data storage system using JSON and files,
meant to be easy to use, strict on typing, and to allow easy migrations via changing properties.

## usage

Create a property dictionary:
```py
from peridata import Property, PersistentStorage

epic_property_dict = {"nuclear_bombs": Property[int](default=1)}
```

Then, create a PersistentStorage instance:
```py
ps = PersistentStorage(epic_property_dict, Path(".") / "data" / "makesurethisisafileloc.json")
```

You can then use it like a dictionary; however, adding new keys will error, and typing is checked:
```py
print(ps["nuclear_bombs"]) # Output: 1 (since it's the default set earlier)
# Wait, we're British. That's it, we're invading France.
ps["nuclear_bombs"] -= 1
print(ps["nuclear_bombs"]) # Output: 0
# I'm gonna make a complex amount of nuclear bombs.
ps["nuclear_bombs"] = 2+1j # TypeError: Invalid type for property 'nuclear_bombs'. Expected int, got complex
# Fine, I'll try to store my tea in here, then.
ps["tea"] = Tea(Tea.Brand.YORKSHIRE, quantity=10000).serialize() # KeyError: 'Invalid property: tea'
```

The data is automatically saved to the file location:
```json
// in data/makesurethisisafileloc.json
{
  "nuclear_bombs": 0
}
```

And, loading the PersistentStorage again will take that instead of the default:
```py
epic_property_dict = {"nuclear_bombs": Property[int](default=1)} # The properties stay the same.
ps = PersistentStorage(epic_property_dict, Path(".") / "data" / "makesurethisisafileloc.json") # The file location is also the same.
print(ps["nuclear_bombs"]) # Output: 0
```

You can also protect data; then, if you use write_unprivileged, you will get an error on writing:

```py
epic_property_dict = {"nuclear_bombs": Property[int](default=1),
                      "tea": Property[str](default=Tea(Tea.Brand.YORKSHIRE, quantity=1).serialize(), protected=True)} # The library will manage setting new dictionary values, if you add them.
ps = PersistentStorage(epic_property_dict, Path(".") / "data" / "makesurethisisafileloc.json") # The file location still the same.
ps.write_unprivileged("nuclear_bombs", 100) # This works, since by default protected=False.
# I'm gonna annoy this brit so hard.
ps.write_unprivileged("tea", Coffee().serialize()) # PermissionError: The property 'tea' is protected and cannot be modified from write_unprivileged().
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "peridata",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "STORAGE",
    "author": null,
    "author_email": "whirlingstars <infernity@infernity.dev>",
    "download_url": "https://files.pythonhosted.org/packages/d3/57/627b3328d6af43be5abb66b58f690cb9a4b3a136da023b88ffb19e3d8d02/peridata-1.1.0.tar.gz",
    "platform": null,
    "description": "# peridata\n\nperidata is a simple, tiny (<4KB!) data storage system using JSON and files,\nmeant to be easy to use, strict on typing, and to allow easy migrations via changing properties.\n\n## usage\n\nCreate a property dictionary:\n```py\nfrom peridata import Property, PersistentStorage\n\nepic_property_dict = {\"nuclear_bombs\": Property[int](default=1)}\n```\n\nThen, create a PersistentStorage instance:\n```py\nps = PersistentStorage(epic_property_dict, Path(\".\") / \"data\" / \"makesurethisisafileloc.json\")\n```\n\nYou can then use it like a dictionary; however, adding new keys will error, and typing is checked:\n```py\nprint(ps[\"nuclear_bombs\"]) # Output: 1 (since it's the default set earlier)\n# Wait, we're British. That's it, we're invading France.\nps[\"nuclear_bombs\"] -= 1\nprint(ps[\"nuclear_bombs\"]) # Output: 0\n# I'm gonna make a complex amount of nuclear bombs.\nps[\"nuclear_bombs\"] = 2+1j # TypeError: Invalid type for property 'nuclear_bombs'. Expected int, got complex\n# Fine, I'll try to store my tea in here, then.\nps[\"tea\"] = Tea(Tea.Brand.YORKSHIRE, quantity=10000).serialize() # KeyError: 'Invalid property: tea'\n```\n\nThe data is automatically saved to the file location:\n```json\n// in data/makesurethisisafileloc.json\n{\n  \"nuclear_bombs\": 0\n}\n```\n\nAnd, loading the PersistentStorage again will take that instead of the default:\n```py\nepic_property_dict = {\"nuclear_bombs\": Property[int](default=1)} # The properties stay the same.\nps = PersistentStorage(epic_property_dict, Path(\".\") / \"data\" / \"makesurethisisafileloc.json\") # The file location is also the same.\nprint(ps[\"nuclear_bombs\"]) # Output: 0\n```\n\nYou can also protect data; then, if you use write_unprivileged, you will get an error on writing:\n\n```py\nepic_property_dict = {\"nuclear_bombs\": Property[int](default=1),\n                      \"tea\": Property[str](default=Tea(Tea.Brand.YORKSHIRE, quantity=1).serialize(), protected=True)} # The library will manage setting new dictionary values, if you add them.\nps = PersistentStorage(epic_property_dict, Path(\".\") / \"data\" / \"makesurethisisafileloc.json\") # The file location still the same.\nps.write_unprivileged(\"nuclear_bombs\", 100) # This works, since by default protected=False.\n# I'm gonna annoy this brit so hard.\nps.write_unprivileged(\"tea\", Coffee().serialize()) # PermissionError: The property 'tea' is protected and cannot be modified from write_unprivileged().\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A tiny dictionary-like file storage system.",
    "version": "1.1.0",
    "project_urls": null,
    "split_keywords": [
        "storage"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e8d99347ad6b2134d817d6a164af93995225c202decb856405580bef67831193",
                "md5": "ac9496453f6e862bb69e4e71aa89792b",
                "sha256": "c0ba659acac171c0cc9c8d40a519ddd0686d8c0404ecf3b67ebcc27219000cfb"
            },
            "downloads": -1,
            "filename": "peridata-1.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ac9496453f6e862bb69e4e71aa89792b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 4347,
            "upload_time": "2024-10-09T07:57:32",
            "upload_time_iso_8601": "2024-10-09T07:57:32.676552Z",
            "url": "https://files.pythonhosted.org/packages/e8/d9/9347ad6b2134d817d6a164af93995225c202decb856405580bef67831193/peridata-1.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d357627b3328d6af43be5abb66b58f690cb9a4b3a136da023b88ffb19e3d8d02",
                "md5": "a3d4362812ef501a16e6700d7a97efea",
                "sha256": "b9e50acde21a82a2fb98e3bd3e34c3fffd2695f8dec23aa9ee07be87b3556b3d"
            },
            "downloads": -1,
            "filename": "peridata-1.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "a3d4362812ef501a16e6700d7a97efea",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4046,
            "upload_time": "2024-10-09T07:57:34",
            "upload_time_iso_8601": "2024-10-09T07:57:34.197697Z",
            "url": "https://files.pythonhosted.org/packages/d3/57/627b3328d6af43be5abb66b58f690cb9a4b3a136da023b88ffb19e3d8d02/peridata-1.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-09 07:57:34",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "peridata"
}
        
Elapsed time: 0.33380s