Skip to main content

Light weight local document-oriented database

Project description

PetDB

PetDB is a simple and lightweight NOSQL JSON database for pet projects. It was designed with the convenient and comfortable mongo-like API. In this package also was implemented simple array with the same API, that supports not only dict documents but any built-in python type.

PyPI - Python Version PyPI - Version Documentation Status PyPI - License Downloads

Installation

PetDB can be installed with pip:

python -m pip install petdb

You can also download the project source and do:

pip install .

Dependencies

PetDB was created as a lightweight package, so there are no dependencies.

Usage

To use this database you should only import PetDB and get an instance. By default, it will create folder for storing collections in the current directory, but you can provide any path:

from petdb import PetDB

db = PetDB.get(os.path.join(os.getcwd(), "persistent", "storage"))

Next you should select the collection, if it doesn't exist, it will created automatically. You can do it just by attribute access, by index key or use a method (it will create a new one if it doesn't exist):

users = db.users
subscriptions = db["subscriptions"]
payments = db.collection("payments")

Examples

>>> from petdb import PetDB
>>> db = PetDB.get()
>>> users = db["users"]
>>> users.insert_many([
...     {"name": "John", "age": 28, "subscriptions": ["tv", "cloud"]},
...     {"name": "Michael", "age": 32, "subscriptions": ["tv"]},
...     {"name": "Sam", "age": 18, "subscriptions": ["music", "cloud"]},
...     {"name": "Alex", "age": 24, "subscriptions": ["tv", "music"]},
...     {"name": "Bob", "age": 18, "subscriptions": ["music"]},
... ])
[{"name": "John", "age": 28, "subscriptions": ["tv", "cloud"], "_id": "..."}, ...]
>>> users.update(
...     {"$append": {"subscriptions": "games"}},
...     {"age": {"$lt": 25}, "subscriptions": {"$contains": "music"}}
... )
>>> selection = users.filter({"age": 18}).sort("name")
>>> print(selection.pick("name").list())
["Bob", "Sam"]
>>> selection.remove()
[{"name": "Bob", "age": 18, "subscriptions": ["music", "games"], "_id": "..."},
{"name": "Sam", "age": 18, "subscriptions": ["music", "cloud", "games"], "_id": "..."}]
>>> for user in users:
...     print(user)
...
{'name': 'John', 'age': 28, 'subscriptions': ['tv', 'cloud'], '_id': '...'}
{'name': 'Michael', 'age': 32, 'subscriptions': ['tv'], '_id': '...'}
{'name': 'Alex', 'age': 24, 'subscriptions': ['tv', 'music', 'games'], '_id': '...'}

Documentation

Documentation is available at https://petdb.readthedocs.io/en/latest/

Testing

python -m tests

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

petdb-0.10.2.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

petdb-0.10.2-py3-none-any.whl (19.1 kB view details)

Uploaded Python 3

File details

Details for the file petdb-0.10.2.tar.gz.

File metadata

  • Download URL: petdb-0.10.2.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.0

File hashes

Hashes for petdb-0.10.2.tar.gz
Algorithm Hash digest
SHA256 f543b3a1b72b83cff3560108cd20e72d2e7705210c4bffff24847d6fecee4bdd
MD5 c9a39fb31c84e9bf14372b1674fa70da
BLAKE2b-256 d3e89664b90fe61a7662487ee80120535d29cb44fb224cbaa9d239d095a56390

See more details on using hashes here.

File details

Details for the file petdb-0.10.2-py3-none-any.whl.

File metadata

  • Download URL: petdb-0.10.2-py3-none-any.whl
  • Upload date:
  • Size: 19.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.0

File hashes

Hashes for petdb-0.10.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c6e81e226a70cd0b3b4939b4ddd129790d6c8dc8fac3b9089d892df0d74e2dc9
MD5 2140b067e3a9e416ea753260210cea9e
BLAKE2b-256 d83f8bdfde6d6dcb3b6bd6c46139004fe83e3d3aa344ce391d2331291910a3a6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page