Skip to main content

EssentialDB - NOSQL document database.

Project description

EssentialDB
============

A Fast Embedded Database in Python.
------------------------------------

Use case: You want to prototype an idea wihtout a heavyweight database install. If the idea works out though, you don't want
to rewrite all of your data access code.

EssentialDB helps solve that problem by being (nearly) api compatible with MongoDB. That way when your idea starts to grow,
you can switch to MongoDB to scale.

* Syntax and semantics are very similar to MongoDB, lowering the barrier of entry.
* Fairly complex query support.
* Its in pure python.
* Its very fast.

`Project On GitHub <https://github.com/shane-mason/essentialdb>`_ |
`Full Docs @ ReadTheDocs <http://essentialdb.readthedocs.io/en/latest/>`_ |
`Distribution On Pypi <https://pypi.python.org/pypi/essentialdb>`_

|Build Status| |Coverage| |Version|

Current Status
---------------
Just getting started!

Quickstart
-----------

Install with pip::

pip install essentialdb


Basic usage is straightforward::

from essentialdb import EssentialDB

#create or open the database
author_db = EssentialDB(filepath="authors.db")

#insert a document into the database
author_db.insert_one({'first': 'Langston', 'last': 'Hughes', 'born': 1902});

#find some entries
results = author_db.find({'last':'Hughes'})

#commit the changes to disk
author_db.sync()

Or using the 'with' semantics to assure that write happen without having to explicitly call sync::

with EssentialDB(filepath="authors.db") as author_db:
author_db.insert_one({'first': 'Langston', 'last': 'Hughes', 'born': 1902});


Insert a document::

author = {'first': 'Langston', 'last': 'Hughes', 'born': 1902}
author_db.insert_one(author)

Insert many documents::

authors = [{'first': 'Langston', 'last': 'Hughes', 'born': 1902},
{'first': 'Ezra', 'last': 'Pound', 'born': 1885}]
author_db.insert_many(authors)

Find one document::

document = author_db.find_one({'first': 'Ezra', 'last': 'Pound'})

Find many::

documents = author_db.find({'born': {'$gt': 1900}})

Update one::

updated = author_db.update({'_id': {'$eq': "A345i"}}, {'born': 1902})

Update many::

updated = author_db.update({'born': {'$gt': 1900}}, {'period': 'Modern'})

Remove Items::

removed = author_db.remove({'period':'Modern'))

Nested Queries::

customer_db.insert_one({'first': 'John', 'last': 'Smith', 'address': { 'street': '10 Maple St', 'city': 'Missoula', 'state': 'MT'}})
results = customer_db.find({'address.state':'MT'})

Note that nested query support means that key names can not include a period.

Write updates to disk::

author_db.sync()

Queries
--------

Queries in EssentialDB follow the same basic form as MongoDB::

{ <field1>: { <operator1>: <value1> }, ... }


Comparison Query Selectors
^^^^^^^^^^^^^^^^^^^^^^^^^^^

The $eq operator matches documents where the value of a field equals the specified value::

author_db.find({"born" : {"$eq": 1972}})

The $ne operator matches documents where the value of a field is not equal to the specified value::

author_db.find({"born" : {"$ne": 1972}})

The $gt operator matches documents where the value of a field is greater than the specified value::

author_db.find({"born" : {"$gt": 1900}})

The $gte operator matches documents where the value of a field is great than or equal to the specified value::

author_db.find({"born" : {"$gte": 1900}})

The $lt operator matches documents where the value of a field is less than the specified value::

author_db.find({"born" : {"$lt": 1900}})


The $lte operator matches documents where the value of a field is less than or equal to the specified value::

author_db.find({"born" : {"$lte": 1900}})

The $in operator matches documents where the value of a field is equal any item in the specified array::

author_db.find({"genre" : {"$in": ["tragedy", "drama"]}})

The $nin operator matches documents where the value of a field is not equal to any item in the specified array::

author_db.find({"genre" : {"$nin": ["tragedy", "drama"]}})


Boolean Operators
^^^^^^^^^^^^^^^^^
The $and operator matches documents where all the fields match::

#find authors born after 1900 and before 2000
author_db.find({'$and':[{'born': {'$gte': 1900}},{'born': {'$lt': 2000}}]})

The $or operator matches documents where any of the fields match::

#find authors with either the first or last name John
author_db.find({'$or':[{'first': {'$eg': 'John'}},{'last': {'$eq': 'John'}}]})

The $nor operator matches document where none of the conditions match::

#find all authors who have neither the first or last name John
author_db.find({"$nor":[{'first': {"$eq": 'John'}},{'last': {'$eq': 'John'}}]})




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

essentialdb-0.3.19.zip (16.0 kB view details)

Uploaded Source

Built Distribution

essentialdb-0.3.19-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file essentialdb-0.3.19.zip.

File metadata

  • Download URL: essentialdb-0.3.19.zip
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for essentialdb-0.3.19.zip
Algorithm Hash digest
SHA256 2ea20871cfe29bfd04ecef026aa7d9a1ec4639295adc2adf5836da1390124b14
MD5 a3040dcf3cd536b19b512a1250448411
BLAKE2b-256 8498df7141c4ac4b6d7d26a76505cd8dd763fe2a3167128188f305b523c67296

See more details on using hashes here.

File details

Details for the file essentialdb-0.3.19-py3-none-any.whl.

File metadata

File hashes

Hashes for essentialdb-0.3.19-py3-none-any.whl
Algorithm Hash digest
SHA256 61144d8d9982bc421a90bb4df1effa18bafc4ba4702cf890dcd6f614acd75647
MD5 5efa6dafbd483617d1845c56624b94d5
BLAKE2b-256 ca1ef06f1bb2d878eb2c17422dd3668e33553d7f0ce8b4f5458a0c8935536667

See more details on using hashes here.

Supported by

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