MoonlightDB


NameMoonlightDB JSON
Version 1.1.1 PyPI version JSON
download
home_pagehttps://github.com/De4oult/Moonlight
SummaryMoonlight is a lightweight JSON-database for Python.
upload_time2024-03-10 19:35:58
maintainer
docs_urlNone
authorde4oult
requires_python>=3.12
licenseMIT License
keywords python cli package json database web interface async python3 python3.12 database-management webinterface moonlight
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Moonlight
<img src="https://i.ibb.co/5k9N9tR/Frame-4.png" alt="Moonlight Logo" height="150" />

<br>

____Moonlight___ is a lightweight JSON-database for Python._

### Installing database library
```bash
pip install Moonlight
```

### Class
Moonlight - database management class

Has the following set of methods:
```Python
0. async push()
1. async all()
2. async get()
3. async update()
5. async delete()
6. async drop()
```

### Creating database
You just need to create an instance of the Moonlight-class, passing the path to the JSON file as an argument.

For example,
```Python
from Moonlight import Moonlight

database: Moonlight = Moonlight('../databases/database.json')
```

#### Arguments
- ___filename___      - path to database .json-file
- ___primary_key___   - primary key name (default: _'id'_) 
- ___show_messages___ - tuple of messages that will be output during operation (default: _('warning', 'error')_)
    * _'success'_
    * _'warning'_
    * _'error'_

<br>

### Methods
<h3>Method examples will be given using the database variable we set. </h3>

### Quick Methods
* ### [0. Moonlight.push](https://github.com/De4oult/Moonlight#push)
* ### [1. Moonlight.all](https://github.com/De4oult/Moonlight#all)
* ### [2. Moonlight.get](https://github.com/De4oult/Moonlight#get)
* ### [3. Moonlight.update](https://github.com/De4oult/Moonlight#update)
* ### [5. Moonlight.delete](https://github.com/De4oult/Moonlight#delete)
* ### [6. Moonlight.drop](https://github.com/De4oult/Moonlight#drop)

#### push()
Adds an object with the given fields to the database <br>

#### Arguments:
* ___data_to_push___ (__dict[str, any]__) - the key-value dictionary to be added to the database

Returns ___id___ (__int__).
<br>

```Python
identifier: int = await database.push(
    {
        'name'       : 'Bertram Gilfoyle',
        'job'        : 'Pied Piper Inc.',
        'occupation' : 'Vice President Of Architecture'
    }
)

print(identifier) 
# output >> 22104564398807 
#           ^^^^^^^^^^^^^^
# ID is 14-digit integer
```

#### all()
Get all objects from the database <br>

Returns ___all_objects___ (__list[dict[str, any]]__)
<br>

```Python
data: list[dict[str, any]] = await database.all()

print(data)
# output >> 
# [
#   {
#       'id': 22104564398807, 
#       'name': 'Bertram Gilfoyle', 
#       'job': 'Pied Piper Inc.', 
#       'occupation': 'Vice President Of Architecture'
#   }
# ]
```

#### get()
Get object/s from the database by query <br>

#### Arguments
- ___query___ (__dict[str, any]__) - the key-value dictionary to find in database

Returns ___object/s___ (__list[dict[str, any]]__).
<br>

```Python
data: list[dict[str, any]] = await database.get({
    'job' : 'Pied Piper Inc.'
})

print(data)
# output >> 
# [
#   {
#       'id': 22104564398807, 
#       'name': 'Bertram Gilfoyle', 
#       'job': 'Pied Piper Inc.', 
#       'occupation': 'Vice President Of Architecture'
#   }
# ]
```

#### update()
Update object in the database <br>

#### Arguments
- ___data_to_update___ (__dict[str, any]__) - the key-value dictionary to change in object in database (___primary_key___ in `data_to_update` required!)

Returns ___id___ (__int__).

<br>

```Python
await database.update(
    {
        'id'         : 22104564398807, 
        'occupation' : 'Network engineer'
    }
)
# changed to >> 
# [
#   {
#       'id': 22104564398807, 
#       'name': 'Bertram Gilfoyle', 
#       'job': 'Pied Piper Inc.', 
#       'occupation': 'Network engineer'
#   }
# ]
```

#### delete()
Remove object from the database <br>

#### Arguments
- ___id___ (__14-digit int__) - identifier of element

Returns ___object___ (__dict[str, any]__)
<br>

```Python
await database.delete(22104564398807)

# database file changed to >> 
# {
#   "data": []
# }
#
# will returned >>
#   {
#       'id': 22104564398807, 
#       'name': 'Bertram Gilfoyle', 
#       'job': 'Pied Piper Inc.', 
#       'occupation': 'Network engineer'
#   }
```

#### drop()
Removes all database data

<br>

```Python
await database.drop()

# database-file writes >>
# {
#   "data": []
# }
```

## Author
```
     _      _  _               _ _   
  __| | ___| || |   ___  _   _| | |_ 
 / _` |/ _ \ || |_ / _ \| | | | | __|
| (_| |  __/__   _| (_) | |_| | | |_ 
 \__,_|\___|  |_|  \___/ \__,_|_|\__|
```

## __Thank you a lot!__

<br>

## How to reach me
<a href="https://t.me/de4oult">
    <img src="https://img.shields.io/badge/-Telegram-informational?style=for-the-badge&logo=telegram" alt="Telegram Badge" height="30" />
</a>
<img src="https://img.shields.io/badge/-kayra.dist@gmail.com-informational?style=for-the-badge&logo=gmail" alt="Gmail Badge" height="30" />

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/De4oult/Moonlight",
    "name": "MoonlightDB",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.12",
    "maintainer_email": "",
    "keywords": "python,cli,package,json,database,web,interface,async,python3,python3.12,database-management,webinterface,moonlight",
    "author": "de4oult",
    "author_email": "kayra.dist@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/e8/fa/c425325caab3eec5e267125124d0e332812228765aef63f3485c89879162/MoonlightDB-1.1.1.tar.gz",
    "platform": null,
    "description": "# Moonlight\r\n<img src=\"https://i.ibb.co/5k9N9tR/Frame-4.png\" alt=\"Moonlight Logo\" height=\"150\" />\r\n\r\n<br>\r\n\r\n____Moonlight___ is a lightweight JSON-database for Python._\r\n\r\n### Installing database library\r\n```bash\r\npip install Moonlight\r\n```\r\n\r\n### Class\r\nMoonlight - database management class\r\n\r\nHas the following set of methods:\r\n```Python\r\n0. async push()\r\n1. async all()\r\n2. async get()\r\n3. async update()\r\n5. async delete()\r\n6. async drop()\r\n```\r\n\r\n### Creating database\r\nYou just need to create an instance of the Moonlight-class, passing the path to the JSON file as an argument.\r\n\r\nFor example,\r\n```Python\r\nfrom Moonlight import Moonlight\r\n\r\ndatabase: Moonlight = Moonlight('../databases/database.json')\r\n```\r\n\r\n#### Arguments\r\n- ___filename___      - path to database .json-file\r\n- ___primary_key___   - primary key name (default: _'id'_) \r\n- ___show_messages___ - tuple of messages that will be output during operation (default: _('warning', 'error')_)\r\n    * _'success'_\r\n    * _'warning'_\r\n    * _'error'_\r\n\r\n<br>\r\n\r\n### Methods\r\n<h3>Method examples will be given using the database variable we set. </h3>\r\n\r\n### Quick Methods\r\n* ### [0. Moonlight.push](https://github.com/De4oult/Moonlight#push)\r\n* ### [1. Moonlight.all](https://github.com/De4oult/Moonlight#all)\r\n* ### [2. Moonlight.get](https://github.com/De4oult/Moonlight#get)\r\n* ### [3. Moonlight.update](https://github.com/De4oult/Moonlight#update)\r\n* ### [5. Moonlight.delete](https://github.com/De4oult/Moonlight#delete)\r\n* ### [6. Moonlight.drop](https://github.com/De4oult/Moonlight#drop)\r\n\r\n#### push()\r\nAdds an object with the given fields to the database <br>\r\n\r\n#### Arguments:\r\n* ___data_to_push___ (__dict[str, any]__) - the key-value dictionary to be added to the database\r\n\r\nReturns ___id___ (__int__).\r\n<br>\r\n\r\n```Python\r\nidentifier: int = await database.push(\r\n    {\r\n        'name'       : 'Bertram Gilfoyle',\r\n        'job'        : 'Pied Piper Inc.',\r\n        'occupation' : 'Vice President Of Architecture'\r\n    }\r\n)\r\n\r\nprint(identifier) \r\n# output >> 22104564398807 \r\n#           ^^^^^^^^^^^^^^\r\n# ID is 14-digit integer\r\n```\r\n\r\n#### all()\r\nGet all objects from the database <br>\r\n\r\nReturns ___all_objects___ (__list[dict[str, any]]__)\r\n<br>\r\n\r\n```Python\r\ndata: list[dict[str, any]] = await database.all()\r\n\r\nprint(data)\r\n# output >> \r\n# [\r\n#   {\r\n#       'id': 22104564398807, \r\n#       'name': 'Bertram Gilfoyle', \r\n#       'job': 'Pied Piper Inc.', \r\n#       'occupation': 'Vice President Of Architecture'\r\n#   }\r\n# ]\r\n```\r\n\r\n#### get()\r\nGet object/s from the database by query <br>\r\n\r\n#### Arguments\r\n- ___query___ (__dict[str, any]__) - the key-value dictionary to find in database\r\n\r\nReturns ___object/s___ (__list[dict[str, any]]__).\r\n<br>\r\n\r\n```Python\r\ndata: list[dict[str, any]] = await database.get({\r\n    'job' : 'Pied Piper Inc.'\r\n})\r\n\r\nprint(data)\r\n# output >> \r\n# [\r\n#   {\r\n#       'id': 22104564398807, \r\n#       'name': 'Bertram Gilfoyle', \r\n#       'job': 'Pied Piper Inc.', \r\n#       'occupation': 'Vice President Of Architecture'\r\n#   }\r\n# ]\r\n```\r\n\r\n#### update()\r\nUpdate object in the database <br>\r\n\r\n#### Arguments\r\n- ___data_to_update___ (__dict[str, any]__) - the key-value dictionary to change in object in database (___primary_key___ in `data_to_update` required!)\r\n\r\nReturns ___id___ (__int__).\r\n\r\n<br>\r\n\r\n```Python\r\nawait database.update(\r\n    {\r\n        'id'         : 22104564398807, \r\n        'occupation' : 'Network engineer'\r\n    }\r\n)\r\n# changed to >> \r\n# [\r\n#   {\r\n#       'id': 22104564398807, \r\n#       'name': 'Bertram Gilfoyle', \r\n#       'job': 'Pied Piper Inc.', \r\n#       'occupation': 'Network engineer'\r\n#   }\r\n# ]\r\n```\r\n\r\n#### delete()\r\nRemove object from the database <br>\r\n\r\n#### Arguments\r\n- ___id___ (__14-digit int__) - identifier of element\r\n\r\nReturns ___object___ (__dict[str, any]__)\r\n<br>\r\n\r\n```Python\r\nawait database.delete(22104564398807)\r\n\r\n# database file changed to >> \r\n# {\r\n#   \"data\": []\r\n# }\r\n#\r\n# will returned >>\r\n#   {\r\n#       'id': 22104564398807, \r\n#       'name': 'Bertram Gilfoyle', \r\n#       'job': 'Pied Piper Inc.', \r\n#       'occupation': 'Network engineer'\r\n#   }\r\n```\r\n\r\n#### drop()\r\nRemoves all database data\r\n\r\n<br>\r\n\r\n```Python\r\nawait database.drop()\r\n\r\n# database-file writes >>\r\n# {\r\n#   \"data\": []\r\n# }\r\n```\r\n\r\n## Author\r\n```\r\n     _      _  _               _ _   \r\n  __| | ___| || |   ___  _   _| | |_ \r\n / _` |/ _ \\ || |_ / _ \\| | | | | __|\r\n| (_| |  __/__   _| (_) | |_| | | |_ \r\n \\__,_|\\___|  |_|  \\___/ \\__,_|_|\\__|\r\n```\r\n\r\n## __Thank you a lot!__\r\n\r\n<br>\r\n\r\n## How to reach me\r\n<a href=\"https://t.me/de4oult\">\r\n    <img src=\"https://img.shields.io/badge/-Telegram-informational?style=for-the-badge&logo=telegram\" alt=\"Telegram Badge\" height=\"30\" />\r\n</a>\r\n<img src=\"https://img.shields.io/badge/-kayra.dist@gmail.com-informational?style=for-the-badge&logo=gmail\" alt=\"Gmail Badge\" height=\"30\" />\r\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "Moonlight is a lightweight JSON-database for Python.",
    "version": "1.1.1",
    "project_urls": {
        "Homepage": "https://github.com/De4oult/Moonlight"
    },
    "split_keywords": [
        "python",
        "cli",
        "package",
        "json",
        "database",
        "web",
        "interface",
        "async",
        "python3",
        "python3.12",
        "database-management",
        "webinterface",
        "moonlight"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ce3a50ee89526a5e2a47ac7977c0070648976532383c8b45fa279168dd1d3150",
                "md5": "a371ae8a87a2371d9e5d200850ed8e08",
                "sha256": "68f6399f4049e4b8b1cfab8197ff53a302e74017093d633aac3cd9f0c8ad1a1f"
            },
            "downloads": -1,
            "filename": "MoonlightDB-1.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a371ae8a87a2371d9e5d200850ed8e08",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.12",
            "size": 7572,
            "upload_time": "2024-03-10T19:35:56",
            "upload_time_iso_8601": "2024-03-10T19:35:56.410717Z",
            "url": "https://files.pythonhosted.org/packages/ce/3a/50ee89526a5e2a47ac7977c0070648976532383c8b45fa279168dd1d3150/MoonlightDB-1.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e8fac425325caab3eec5e267125124d0e332812228765aef63f3485c89879162",
                "md5": "11a3b78099611ac962a1f4a4e072ee94",
                "sha256": "cd85029265eb0b76f1b94995bb0ec2bebdd6862c07a04a2dc67ae67537702db9"
            },
            "downloads": -1,
            "filename": "MoonlightDB-1.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "11a3b78099611ac962a1f4a4e072ee94",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.12",
            "size": 6441,
            "upload_time": "2024-03-10T19:35:58",
            "upload_time_iso_8601": "2024-03-10T19:35:58.008279Z",
            "url": "https://files.pythonhosted.org/packages/e8/fa/c425325caab3eec5e267125124d0e332812228765aef63f3485c89879162/MoonlightDB-1.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-10 19:35:58",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "De4oult",
    "github_project": "Moonlight",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "moonlightdb"
}
        
Elapsed time: 0.20932s