fastjson-db


Namefastjson-db JSON
Version 0.2.1 PyPI version JSON
download
home_pageNone
SummaryA lightweight JSON database with dataclass support.
upload_time2025-09-03 04:28:41
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseMIT License Copyright (c) 2025 Heisdoffer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # FastJson-db #

A lightweight JSON-based database for Python.  
`fastjson-db` allows you to store, retrieve, and manipulate data in a simple JSON file with a minimal and easy-to-use API.

## Features ##

- Lightweight and simple to use
- CRUD operations: insert, get, update, delete
- Automatic unique IDs for records
- Optional fast backend using `orjson` if installed
- Human-readable JSON file

## Installation ##

```bash
pip install fastjson-db
```

## Documentation ##

For further information, see the docs/ folder on github.

## Examples ##

Some basic examples on how to user FastJson-db

### Creating a Class ###

To manipulate JsonTables, you need to create a JsonModel subclass (dataclass), so the JsonTable only accepts that especific JsonModel subclass.

```py
from fastjson_db import JsonModel
from dataclasses import dataclass

@dataclass
class User(JsonModel):
    _id: int
    name: str = ""
    password: str = ""
```

It's obrigatory using `_id` field or it will not result in error when quering.

### Creating a JsonTable ###

JsonTables are the ones inserting and updating your dataclasses in .json files. They will automaticly create and facilitate the usage of .json "tables", trying to simulate a simple database.

```py
from fastjson_db import JsonModel, JsonTable
from dataclasses import dataclass

@dataclass
class User(JsonModel):
    _id: int = 0
    name: str = ""
    password: str = ""
    
user = User(name="Allan", password="123")

user_table = JsonTable("users.json", User)
```

For easier table manipulation and avoid various JsonTables manipulating the same .json table, register the table in TABLE_REGISTRY.

```py
TABLE_REGISTRY[User] = user_table
```

### Creating a JsonQuerier ###

JsonQueriers will make queries and searchs in the .json files / tables.

```py
from fastjson_db import JsonModel, JsonTable, JsonQuerier
from dataclasses import dataclass

@dataclass
class User(JsonModel):
    _id: int = 0
    name: str = ""
    password: str = ""
    age: int = 0

user_table = JsonTable("users.json", User)
TABLE_REGISTRY[User] = user_table

user_table.insert(User(_id=1, name="Alice", password="abc", age=25))
user_table.insert(User(_id=2, name="Bob", password="123", age=30))
user_table.insert(User(_id=3, name="Charlie", password="xyz", age=35))

querier = JsonQuerier(user_table)

alice = querier.filter(name="Alice")
print("Filter:", alice)

not_30 = querier.exclude(age=30)
print("Exclude:", not_30)

older_than_30 = querier.custom(lambda u: u.age > 30)
print("Custom:", older_than_30)

bob = querier.get_first(name="Bob")
print("Get first:", bob)

ordered = querier.order_by("age")
print("Order by age:", ordered)
```

These are the main functions of JsonQuerier. You can have multiple queriers in the same table without generating Exceptions, but it's not recomended.

### Using a ForeignKey ###

FastJson-db tries to simulate ForeignKeys with a class called ForeignKey. You need to just create a ForeignKey field with the JsonModel it's related to.

```py
from fastjson_db import JsonModel, JsonTable, ForeignKey
from dataclasses import dataclass

@dataclass
class User(JsonModel):
    _id: int = 0
    name: str = ""

@dataclass
class Post(JsonModel):
    _id: int = 0
    title: str = ""
    author: ForeignKey[User] = ForeignKey(User)

user_table = JsonTable("users.json", User)
post_table = JsonTable("posts.json", Post)
TABLE_REGISTRY[User] = user_table
TABLE_REGISTRY[Post] = post_table

alice = User(_id=1, name="Alice")
user_table.insert(alice)

post = Post(_id=1, title="Meu primeiro post")
post.author.set(alice)
post_table.insert(post)

retrieved_post = post_table.get_first(_id=1)
author = retrieved_post.author.get()
print("Post:", retrieved_post.title)
print("Author:", author.name if author else "None")
```

So in this example we user a basic query to find a "Author" in the Post Table.

## Changelog ##

For a complete list of changes and updates, see the [CHANGELOG](CHANGELOG.md) file.

## Roadmap ##

For a complete list of future updates and how you can help, see [ROADMAP](ROADMAP.md) and [CONTRIBUTING](CONTRIBUTING.md) files.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "fastjson-db",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": "Maur\u00edcio Reisdoefer <mauricio.reisdoefer2009@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/9c/84/f72eae383567ea26130c2002e7aeb880f31babe151f9a202e7497986a4e6/fastjson_db-0.2.1.tar.gz",
    "platform": null,
    "description": "# FastJson-db #\r\n\r\nA lightweight JSON-based database for Python.  \r\n`fastjson-db` allows you to store, retrieve, and manipulate data in a simple JSON file with a minimal and easy-to-use API.\r\n\r\n## Features ##\r\n\r\n- Lightweight and simple to use\r\n- CRUD operations: insert, get, update, delete\r\n- Automatic unique IDs for records\r\n- Optional fast backend using `orjson` if installed\r\n- Human-readable JSON file\r\n\r\n## Installation ##\r\n\r\n```bash\r\npip install fastjson-db\r\n```\r\n\r\n## Documentation ##\r\n\r\nFor further information, see the docs/ folder on github.\r\n\r\n## Examples ##\r\n\r\nSome basic examples on how to user FastJson-db\r\n\r\n### Creating a Class ###\r\n\r\nTo manipulate JsonTables, you need to create a JsonModel subclass (dataclass), so the JsonTable only accepts that especific JsonModel subclass.\r\n\r\n```py\r\nfrom fastjson_db import JsonModel\r\nfrom dataclasses import dataclass\r\n\r\n@dataclass\r\nclass User(JsonModel):\r\n    _id: int\r\n    name: str = \"\"\r\n    password: str = \"\"\r\n```\r\n\r\nIt's obrigatory using `_id` field or it will not result in error when quering.\r\n\r\n### Creating a JsonTable ###\r\n\r\nJsonTables are the ones inserting and updating your dataclasses in .json files. They will automaticly create and facilitate the usage of .json \"tables\", trying to simulate a simple database.\r\n\r\n```py\r\nfrom fastjson_db import JsonModel, JsonTable\r\nfrom dataclasses import dataclass\r\n\r\n@dataclass\r\nclass User(JsonModel):\r\n    _id: int = 0\r\n    name: str = \"\"\r\n    password: str = \"\"\r\n    \r\nuser = User(name=\"Allan\", password=\"123\")\r\n\r\nuser_table = JsonTable(\"users.json\", User)\r\n```\r\n\r\nFor easier table manipulation and avoid various JsonTables manipulating the same .json table, register the table in TABLE_REGISTRY.\r\n\r\n```py\r\nTABLE_REGISTRY[User] = user_table\r\n```\r\n\r\n### Creating a JsonQuerier ###\r\n\r\nJsonQueriers will make queries and searchs in the .json files / tables.\r\n\r\n```py\r\nfrom fastjson_db import JsonModel, JsonTable, JsonQuerier\r\nfrom dataclasses import dataclass\r\n\r\n@dataclass\r\nclass User(JsonModel):\r\n    _id: int = 0\r\n    name: str = \"\"\r\n    password: str = \"\"\r\n    age: int = 0\r\n\r\nuser_table = JsonTable(\"users.json\", User)\r\nTABLE_REGISTRY[User] = user_table\r\n\r\nuser_table.insert(User(_id=1, name=\"Alice\", password=\"abc\", age=25))\r\nuser_table.insert(User(_id=2, name=\"Bob\", password=\"123\", age=30))\r\nuser_table.insert(User(_id=3, name=\"Charlie\", password=\"xyz\", age=35))\r\n\r\nquerier = JsonQuerier(user_table)\r\n\r\nalice = querier.filter(name=\"Alice\")\r\nprint(\"Filter:\", alice)\r\n\r\nnot_30 = querier.exclude(age=30)\r\nprint(\"Exclude:\", not_30)\r\n\r\nolder_than_30 = querier.custom(lambda u: u.age > 30)\r\nprint(\"Custom:\", older_than_30)\r\n\r\nbob = querier.get_first(name=\"Bob\")\r\nprint(\"Get first:\", bob)\r\n\r\nordered = querier.order_by(\"age\")\r\nprint(\"Order by age:\", ordered)\r\n```\r\n\r\nThese are the main functions of JsonQuerier. You can have multiple queriers in the same table without generating Exceptions, but it's not recomended.\r\n\r\n### Using a ForeignKey ###\r\n\r\nFastJson-db tries to simulate ForeignKeys with a class called ForeignKey. You need to just create a ForeignKey field with the JsonModel it's related to.\r\n\r\n```py\r\nfrom fastjson_db import JsonModel, JsonTable, ForeignKey\r\nfrom dataclasses import dataclass\r\n\r\n@dataclass\r\nclass User(JsonModel):\r\n    _id: int = 0\r\n    name: str = \"\"\r\n\r\n@dataclass\r\nclass Post(JsonModel):\r\n    _id: int = 0\r\n    title: str = \"\"\r\n    author: ForeignKey[User] = ForeignKey(User)\r\n\r\nuser_table = JsonTable(\"users.json\", User)\r\npost_table = JsonTable(\"posts.json\", Post)\r\nTABLE_REGISTRY[User] = user_table\r\nTABLE_REGISTRY[Post] = post_table\r\n\r\nalice = User(_id=1, name=\"Alice\")\r\nuser_table.insert(alice)\r\n\r\npost = Post(_id=1, title=\"Meu primeiro post\")\r\npost.author.set(alice)\r\npost_table.insert(post)\r\n\r\nretrieved_post = post_table.get_first(_id=1)\r\nauthor = retrieved_post.author.get()\r\nprint(\"Post:\", retrieved_post.title)\r\nprint(\"Author:\", author.name if author else \"None\")\r\n```\r\n\r\nSo in this example we user a basic query to find a \"Author\" in the Post Table.\r\n\r\n## Changelog ##\r\n\r\nFor a complete list of changes and updates, see the [CHANGELOG](CHANGELOG.md) file.\r\n\r\n## Roadmap ##\r\n\r\nFor a complete list of future updates and how you can help, see [ROADMAP](ROADMAP.md) and [CONTRIBUTING](CONTRIBUTING.md) files.\r\n",
    "bugtrack_url": null,
    "license": "MIT License\r\n        \r\n        Copyright (c) 2025 Heisdoffer\r\n        \r\n        Permission is hereby granted, free of charge, to any person obtaining a copy\r\n        of this software and associated documentation files (the \"Software\"), to deal\r\n        in the Software without restriction, including without limitation the rights\r\n        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\n        copies of the Software, and to permit persons to whom the Software is\r\n        furnished to do so, subject to the following conditions:\r\n        \r\n        The above copyright notice and this permission notice shall be included in all\r\n        copies or substantial portions of the Software.\r\n        \r\n        THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\n        SOFTWARE.\r\n        ",
    "summary": "A lightweight JSON database with dataclass support.",
    "version": "0.2.1",
    "project_urls": {
        "Bug Tracker": "https://github.com/MauricioReisdoefer/jsonlite/issues",
        "Homepage": "https://github.com/MauricioReisdoefer/jsonlite"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "3e4a70db17e3ac6d3342c900e4083cf384ecc27c0c562d58f5944d9b9eca9c9d",
                "md5": "cd2875ad5d624317f5de96d94c7c92af",
                "sha256": "8cac8c62309461f02f014e649f806fa866640af67100e229cb286e61e47ebf0f"
            },
            "downloads": -1,
            "filename": "fastjson_db-0.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "cd2875ad5d624317f5de96d94c7c92af",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 10102,
            "upload_time": "2025-09-03T04:28:40",
            "upload_time_iso_8601": "2025-09-03T04:28:40.289145Z",
            "url": "https://files.pythonhosted.org/packages/3e/4a/70db17e3ac6d3342c900e4083cf384ecc27c0c562d58f5944d9b9eca9c9d/fastjson_db-0.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "9c84f72eae383567ea26130c2002e7aeb880f31babe151f9a202e7497986a4e6",
                "md5": "8a34535e4c2e6bf9cc16d851efce43bf",
                "sha256": "219ea9ee8b7a6d2b50564ad94402e7e740d11692fae8c9f816c95a8d7ce63cfd"
            },
            "downloads": -1,
            "filename": "fastjson_db-0.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "8a34535e4c2e6bf9cc16d851efce43bf",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 9905,
            "upload_time": "2025-09-03T04:28:41",
            "upload_time_iso_8601": "2025-09-03T04:28:41.801293Z",
            "url": "https://files.pythonhosted.org/packages/9c/84/f72eae383567ea26130c2002e7aeb880f31babe151f9a202e7497986a4e6/fastjson_db-0.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-09-03 04:28:41",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "MauricioReisdoefer",
    "github_project": "jsonlite",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "fastjson-db"
}
        
Elapsed time: 1.69678s