Skip to main content

A pure Python document and graph database engine

Project description

DocNetDB

A pure Python document and graph database engine

The graph part is coming soon.

Features

Strengths :

  • In one readable file
  • The Vertex class is subclassable

Weaknesses :

  • Due to its design, not fast as light

Usage

Creating a DocNetDB object

from docnetdb import DocNetDB, Vertex

# Use a string
database = DocNetDB("subfolder/file.ext")
# Or a Path
import pathlib
database = pathlib.Path(".") / "subfolder" / "file.ext"

Creating vertices

# Element assignment with item style
rush_hour = Vertex()
rush_hour["name"] = "Rush Hour"
rush_hour["length"] = 5.25
rush_hour["url"] = "https://www.youtube.com/watch?v=OXBcBugpHZg"

# Element assignment with initial data dict
initial_data = dict(
    name="Nyakuza Manholes",
    length=6.62,
    url="https://www.youtube.com/watch?v=GDxS8oK6hCc"
)
manholes = Vertex(initial_data)
# Or
manholes = Vertex.from_dict(initial_data)

Insert vertices in the database

rush_hour.is_inserted() # Returns False
database.insert(rush_hour) # Returns the place (1 in this case)
rush_hour.is_inserted() # Returns True
rush_hour.place # Returns 1

database.insert(manholes) # Returns the place (2 in this case)

# You can still add elements to a Vertex afterwards
rush_hour is database[1] # Returns True
manholes is database[2] # Returns True

Save the database to the file

database.save()

Access vertices in the database

# Get the first vertex
database[1]

# Get the vertices that have a length superior to 4 minutes
def custom_gate(vertex):
    return vertex["length"] > 4
gen = database.search(custom_gate) # Returns a generator

# It doesn't matter if a vertex doesn't have a "length" element, as the
# KeyError is automatically captured.

# Delete the filtered vertices (just "manholes" in this case)
for vertex in gen:
    database.remove(vertex)

# "manholes" still exists, it was just detached from the database.
manholes["name"] # Returns "Nyakuza Manholes"
manholes.is_inserted() # Returns False

Project details


Download files

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

Files for docnetdb, version 0.2
Filename, size File type Python version Upload date Hashes
Filename, size docnetdb-0.2-py3-none-any.whl (8.0 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size docnetdb-0.2.tar.gz (6.0 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page