jsondb-python


Namejsondb-python JSON
Version 1.0.9 PyPI version JSON
download
home_pagehttps://github.com/Elang-elang/JsonDB
SummaryA simple, lightweight, and file-based JSON database library for Python.
upload_time2025-07-11 16:29:50
maintainerNone
docs_urlNone
authorElang Muhammad
requires_python>=3.8
licenseMIT License Copyright (c) 2025 Elang Muhammad 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 json database file-based nosql db
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <p align="center">
  <a href="https://pypi.org/project/jsondb-python">
    <img src="https://raw.githubusercontent.com/Elang-elang/JsonDB/refs/heads/main/icons/icon2.png?token=GHSAT0AAAAAADGRQCSXNYSVVQWA6VZJUYB42DMFE2A" alt="JsonDB Logo">
  </a>
</p>

<h1 align="center">JsonDB-Python</h1>

<p align="center">
  <a href="https://pypi.org/project/jsondb-python">
    <img src="https://img.shields.io/pypi/v/jsondb-python.svg?label=PyPI" alt="PyPI Version">
  </a>
  <a href="https://github.com/Elang-elang/JsonDB-Python/blob/main/LICENSE">
    <img src="https://img.shields.io/badge/License-MIT-purple.svg" alt="License">
  </a>
  <a href="https://jsondb-docs.netlify.app">
    <img src="https://img.shields.io/badge/Documentation-passing-brightgreen" alt="Documentation">
  </a>
</p>

A simple, lightweight, and file-based JSON database library for Python, now with proper error handling, a modular structure, and a powerful interactive REPL.

## Overview

`jsondb-python` provides two ways to manage your data:

1.  **As a Python Library:** A simple interface for storing and retrieving data in a JSON file. It's perfect for small projects where a full-fledged database is overkill.
2.  **As an Interactive REPL:** A feature-rich command-line interface (CLI) to manage your databases directly from the terminal, no scripting required.

## Installation

```bash
pip install jsondb-python
```
For the best REPL experience with auto-completion and history, it is recommended to install `prompt_toolkit`:
```bash
pip install prompt-toolkit
```

## Usage

### As a Python Library (Quick Start)

```python
from jsondb import JsonDB

# Initialize the database
db = JsonDB('my_database.json')

try:
    # Create a table
    db.create_table('users')

    # Insert data
    db.insert_data('users', {'id': 1, 'name': 'Alice', 'role': 'admin'})
    db.insert_data('users', {'id': 2, 'name': 'Bob', 'role': 'user'})

    # Update data where role is 'user'
    db.update_data(
        'users',
        condition=lambda user: user.get('role') == 'user',
        new_data={'id': 2, 'name': 'Bob', 'role': 'member'}
    )

    # Delete data where id is 1
    db.delete_data('users', condition=lambda user: user.get('id') == 1)

    # Show final data
    db.show_data('users')

except db.TableExistsError as e:
    print(f"Setup failed because a table already exists: {e}")
except db.Error as e: # Catch any library-specific error
    print(f"An error occurred with the database: {e}")
except Exception as e:
    print(f"A general error occurred: {e}")

```

### Interactive REPL (CLI)

The library includes a powerful interactive REPL (Read-Eval-Print Loop) to manage your databases from the command line.

**Launching the REPL:**

```bash
# Start the REPL in the main menu
jsondb

# Or open a database file directly
jsondb ./path/to/your/database.json
```

**Key Features:**

*   **Interactive Management:** Create, edit, and manage your JSON databases without writing Python code.
*   **Smart Auto-Completion:** Press `Tab` to get suggestions for commands, file paths, and table names.
*   **Command History:** Use the Up/Down arrow keys to navigate your command history.
*   **User-Friendly Interface:** A colorized and structured interface makes database management easy.
*   **Built-in Help:** Type `.help` in any mode to see a list of available commands.
*   **Safe Operations:** Features auto-saving on exit and automatic backup creation to prevent data loss.

**Example Session:**

```bash
$ jsondb
🌟 JsonDB >>> .build
📁 Enter database path (example: data/mydb.json): users.json
✅ Database 'users.json' created/opened successfully!
💡 Use '.create <table_name>' to create a new table
📦 [users.json] >>> .create people
✅ Table 'people' created successfully!
📦 [users.json] >>> .use people
✅ Successfully selected table 'people'!
💡 Use '.insert' to add data
📋 [people] >>> .insert
# ... interactive prompt to add data ...
✅ Data added successfully!
📋 [people] >>> .show
# ... displays table data ...
📋 [people] >>> .exit
💾 Performing auto-save before exiting...
👋 Thank you for using JsonDB REPL!
💾 Your data has been safely saved
```

## License

This project is licensed under the MIT License. See the [LICENSE](https://github.com/Elang-elang/JsonDB-Python/blob/main/LICENSE) file for details.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Elang-elang/JsonDB",
    "name": "jsondb-python",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "json, database, file-based, nosql, db",
    "author": "Elang Muhammad",
    "author_email": "Elang Muhammad <elangmuhammad888@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/24/c9/6f972101357eb83eb0abc8010f37ff3c41819fa0b5df91a2e1a36b350473/jsondb_python-1.0.9.tar.gz",
    "platform": null,
    "description": "<p align=\"center\">\n  <a href=\"https://pypi.org/project/jsondb-python\">\n    <img src=\"https://raw.githubusercontent.com/Elang-elang/JsonDB/refs/heads/main/icons/icon2.png?token=GHSAT0AAAAAADGRQCSXNYSVVQWA6VZJUYB42DMFE2A\" alt=\"JsonDB Logo\">\n  </a>\n</p>\n\n<h1 align=\"center\">JsonDB-Python</h1>\n\n<p align=\"center\">\n  <a href=\"https://pypi.org/project/jsondb-python\">\n    <img src=\"https://img.shields.io/pypi/v/jsondb-python.svg?label=PyPI\" alt=\"PyPI Version\">\n  </a>\n  <a href=\"https://github.com/Elang-elang/JsonDB-Python/blob/main/LICENSE\">\n    <img src=\"https://img.shields.io/badge/License-MIT-purple.svg\" alt=\"License\">\n  </a>\n  <a href=\"https://jsondb-docs.netlify.app\">\n    <img src=\"https://img.shields.io/badge/Documentation-passing-brightgreen\" alt=\"Documentation\">\n  </a>\n</p>\n\nA simple, lightweight, and file-based JSON database library for Python, now with proper error handling, a modular structure, and a powerful interactive REPL.\n\n## Overview\n\n`jsondb-python` provides two ways to manage your data:\n\n1.  **As a Python Library:** A simple interface for storing and retrieving data in a JSON file. It's perfect for small projects where a full-fledged database is overkill.\n2.  **As an Interactive REPL:** A feature-rich command-line interface (CLI) to manage your databases directly from the terminal, no scripting required.\n\n## Installation\n\n```bash\npip install jsondb-python\n```\nFor the best REPL experience with auto-completion and history, it is recommended to install `prompt_toolkit`:\n```bash\npip install prompt-toolkit\n```\n\n## Usage\n\n### As a Python Library (Quick Start)\n\n```python\nfrom jsondb import JsonDB\n\n# Initialize the database\ndb = JsonDB('my_database.json')\n\ntry:\n    # Create a table\n    db.create_table('users')\n\n    # Insert data\n    db.insert_data('users', {'id': 1, 'name': 'Alice', 'role': 'admin'})\n    db.insert_data('users', {'id': 2, 'name': 'Bob', 'role': 'user'})\n\n    # Update data where role is 'user'\n    db.update_data(\n        'users',\n        condition=lambda user: user.get('role') == 'user',\n        new_data={'id': 2, 'name': 'Bob', 'role': 'member'}\n    )\n\n    # Delete data where id is 1\n    db.delete_data('users', condition=lambda user: user.get('id') == 1)\n\n    # Show final data\n    db.show_data('users')\n\nexcept db.TableExistsError as e:\n    print(f\"Setup failed because a table already exists: {e}\")\nexcept db.Error as e: # Catch any library-specific error\n    print(f\"An error occurred with the database: {e}\")\nexcept Exception as e:\n    print(f\"A general error occurred: {e}\")\n\n```\n\n### Interactive REPL (CLI)\n\nThe library includes a powerful interactive REPL (Read-Eval-Print Loop) to manage your databases from the command line.\n\n**Launching the REPL:**\n\n```bash\n# Start the REPL in the main menu\njsondb\n\n# Or open a database file directly\njsondb ./path/to/your/database.json\n```\n\n**Key Features:**\n\n*   **Interactive Management:** Create, edit, and manage your JSON databases without writing Python code.\n*   **Smart Auto-Completion:** Press `Tab` to get suggestions for commands, file paths, and table names.\n*   **Command History:** Use the Up/Down arrow keys to navigate your command history.\n*   **User-Friendly Interface:** A colorized and structured interface makes database management easy.\n*   **Built-in Help:** Type `.help` in any mode to see a list of available commands.\n*   **Safe Operations:** Features auto-saving on exit and automatic backup creation to prevent data loss.\n\n**Example Session:**\n\n```bash\n$ jsondb\n\ud83c\udf1f JsonDB >>> .build\n\ud83d\udcc1 Enter database path (example: data/mydb.json): users.json\n\u2705 Database 'users.json' created/opened successfully!\n\ud83d\udca1 Use '.create <table_name>' to create a new table\n\ud83d\udce6 [users.json] >>> .create people\n\u2705 Table 'people' created successfully!\n\ud83d\udce6 [users.json] >>> .use people\n\u2705 Successfully selected table 'people'!\n\ud83d\udca1 Use '.insert' to add data\n\ud83d\udccb [people] >>> .insert\n# ... interactive prompt to add data ...\n\u2705 Data added successfully!\n\ud83d\udccb [people] >>> .show\n# ... displays table data ...\n\ud83d\udccb [people] >>> .exit\n\ud83d\udcbe Performing auto-save before exiting...\n\ud83d\udc4b Thank you for using JsonDB REPL!\n\ud83d\udcbe Your data has been safely saved\n```\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](https://github.com/Elang-elang/JsonDB-Python/blob/main/LICENSE) file for details.\n",
    "bugtrack_url": null,
    "license": "MIT License\n        \n        Copyright (c) 2025 Elang Muhammad\n        \n        Permission is hereby granted, free of charge, to any person obtaining a copy\n        of this software and associated documentation files (the \"Software\"), to deal\n        in the Software without restriction, including without limitation the rights\n        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n        copies of the Software, and to permit persons to whom the Software is\n        furnished to do so, subject to the following conditions:\n        \n        The above copyright notice and this permission notice shall be included in all\n        copies or substantial portions of the Software.\n        \n        THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n        SOFTWARE.\n        ",
    "summary": "A simple, lightweight, and file-based JSON database library for Python.",
    "version": "1.0.9",
    "project_urls": {
        "Homepage": "https://github.com/Elang-elang/",
        "Issues": "https://github.com/Elang-elang/JsonDB/issues",
        "Repository": "https://github.com/Elang-elang/JsonDB"
    },
    "split_keywords": [
        "json",
        " database",
        " file-based",
        " nosql",
        " db"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "27442a987664edaf126463e92e0c98cb15a55dc5395dc31d7db7a6ab0e6a27bb",
                "md5": "bfe0ed201ed2daa54a3626cac53ff2b6",
                "sha256": "06ca52e13746c5e3626a00bc9992d2b84b325533f6d5f967c249d6dcfeca16d7"
            },
            "downloads": -1,
            "filename": "jsondb_python-1.0.9-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "bfe0ed201ed2daa54a3626cac53ff2b6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 20808,
            "upload_time": "2025-07-11T16:29:48",
            "upload_time_iso_8601": "2025-07-11T16:29:48.453561Z",
            "url": "https://files.pythonhosted.org/packages/27/44/2a987664edaf126463e92e0c98cb15a55dc5395dc31d7db7a6ab0e6a27bb/jsondb_python-1.0.9-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "24c96f972101357eb83eb0abc8010f37ff3c41819fa0b5df91a2e1a36b350473",
                "md5": "f5e141f9c2701779a5d29e31cfff6e74",
                "sha256": "cc8ebdc78b6351ead69cc0356f02214c1fe2d9195e70bcf1b4f11bdcea87b5ca"
            },
            "downloads": -1,
            "filename": "jsondb_python-1.0.9.tar.gz",
            "has_sig": false,
            "md5_digest": "f5e141f9c2701779a5d29e31cfff6e74",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 21169,
            "upload_time": "2025-07-11T16:29:50",
            "upload_time_iso_8601": "2025-07-11T16:29:50.084954Z",
            "url": "https://files.pythonhosted.org/packages/24/c9/6f972101357eb83eb0abc8010f37ff3c41819fa0b5df91a2e1a36b350473/jsondb_python-1.0.9.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-11 16:29:50",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Elang-elang",
    "github_project": "JsonDB",
    "github_not_found": true,
    "lcname": "jsondb-python"
}
        
Elapsed time: 1.30162s