peridata


Nameperidata JSON
Version 1.3.3 PyPI version JSON
download
home_pageNone
SummaryA tiny dictionary-like file storage system.
upload_time2025-01-04 23:27:00
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 (<5KiB!) 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/ba/7c/aa82228cc2b699d771836ed686a2e581cd50ef1f17639644f9ab1d525690/peridata-1.3.3.tar.gz",
    "platform": null,
    "description": "# peridata\n\nperidata is a simple, tiny (<5KiB!) 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.3.3",
    "project_urls": null,
    "split_keywords": [
        "storage"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "abf38325576ecde11fb12679508f8d84d16bae8fa8ad11d1a1fd8d1258a968ac",
                "md5": "99b75773b2e520cf964dcb445b460af4",
                "sha256": "3cdd4fe55362eb99c59d56a85a5fe2e43704af1d54fad729be4cea00de1cf2e0"
            },
            "downloads": -1,
            "filename": "peridata-1.3.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "99b75773b2e520cf964dcb445b460af4",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 4501,
            "upload_time": "2025-01-04T23:26:58",
            "upload_time_iso_8601": "2025-01-04T23:26:58.026192Z",
            "url": "https://files.pythonhosted.org/packages/ab/f3/8325576ecde11fb12679508f8d84d16bae8fa8ad11d1a1fd8d1258a968ac/peridata-1.3.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ba7caa82228cc2b699d771836ed686a2e581cd50ef1f17639644f9ab1d525690",
                "md5": "25802560c0e716814a7975a832b38454",
                "sha256": "f7086f11a98e9142f802a27e0b411b4949ce38c351763d944a31e1f7312b51ab"
            },
            "downloads": -1,
            "filename": "peridata-1.3.3.tar.gz",
            "has_sig": false,
            "md5_digest": "25802560c0e716814a7975a832b38454",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4182,
            "upload_time": "2025-01-04T23:27:00",
            "upload_time_iso_8601": "2025-01-04T23:27:00.072763Z",
            "url": "https://files.pythonhosted.org/packages/ba/7c/aa82228cc2b699d771836ed686a2e581cd50ef1f17639644f9ab1d525690/peridata-1.3.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-04 23:27:00",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "peridata"
}
        
Elapsed time: 0.40342s