A clean graph database engine
Project description
Graphite
A clean graph database engine!
Graphite is a simple yet flexible Graph Database Engine that is implemented in Python. This engine uses basic structures (similar to classes in programming languages) for nodes and connections (equivalent to Edges in other engines).
Features
- Structure-oriented: Define node types and relation types in structure, define fields, base type, and valid forms.
- Base Node Type: Create base type for node types to add base properties and advanced relations.
- First-class Nodes: Create nodes from node types and fill data fields.
- Relations with Properties: Like nodes, relations can have properties too.
- Simple Syntax: The most simple syntaxes in all steps.
- Serializable: Save whole database into one file.
- And much more...
Installation
Install package from Python Package Index:
pip install graphitedb
Example Usage
import graphite
def example_complete_dsl_loading():
engine = graphite.engine()
complete_dsl = """
# Define node types
node Person
name: string
age: int
node User from Person
id: string
email: string
node Object
node Book from Object
title: string
n_pages: int
node Car from Object
model: string
year: int
# Define relation types
relation FRIEND both
Person - Person
since: date
relation OWNER reverse OWNED_BY
Person -> Object
since: date
purchased_at: date
relation AUTHOR reverse AUTHORED_BY
Person -> Book
year: int
# Create node instances
User, user_1, "Joe Doe", 32, "joe4030", "joe@email.com"
User, user_2, "Jane Smith", 28, "jane28", "jane@email.com"
User, user_3, "Bob Wilson", 45, "bob45", "bob@email.com"
User, user_4, "Alice Brown", 22, "alice22", "alice@email.com"
Book, book_1, "The Great Gatsby", 180
Book, book_2, "Python Programming", 450
Book, book_3, "Graph Databases", 320
Car, car_1, "Toyota Camry", 2020
Car, car_2, "Honda Civic", 2018
# Create relation instances
user_1 -[FRIEND, 2020-05-15]- user_2
user_1 -[FRIEND, 2019-08-22]- user_3
user_2 -[FRIEND, 2021-01-10]- user_4
user_1 -[OWNER, 2021-03-01, 2021-02-15]-> car_1
user_2 -[OWNER, 2019-06-20, 2019-05-10]-> book_1
user_3 -[OWNER, 2022-11-05, 2022-10-20]-> book_2
user_1 -[AUTHOR, 2020]-> book_3
user_2 -[AUTHOR, 2021]-> book_2
# Alternative syntax (reverse relation)
book_1 -[OWNED_BY, 2019-06-20, 2019-05-10]-> user_2
car_2 -[OWNED_BY, 2018-12-01, 2018-11-15]-> user_4
"""
# Load all with one call
engine.load_dsl(complete_dsl)
print("=== Database Stats ===")
stats = engine.stats()
print(f"Node Types: {stats['node_types']}")
print(f"Relation Types: {stats['relation_types']}")
print(f"Nodes: {stats['nodes']}")
print(f"Relations: {stats['relations']}")
print("\n=== Query Examples ===")
# All users
users = engine.query.User.get()
print(f"All Users ({len(users)}): {[u['name'] for u in users]}")
# Users with more than 30 years age
older_users = engine.query.User.where("age > 30").get()
print(f"\nUsers over 30: {[u['name'] for u in older_users]}")
# Joe Doe books
joe_books = (engine.query.User
.where(lambda u: u['name'] == "Joe Doe")
.outgoing("AUTHOR")
.get())
print(f"\nBooks authored by Joe Doe: {[b['title'] for b in joe_books]}")
# Two steps traverse
friends_of_friends = (engine.query.User
.where(lambda u: u['name'] == "Joe Doe")
.outgoing("FRIEND")
.outgoing("FRIEND")
.distinct()
.get())
print(f"\nFriends of friends of Joe Doe: {[f['name'] for f in friends_of_friends]}")
return engine
You can see more examples in example.py in GitHub repo.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file graphitedb-0.1.1.tar.gz.
File metadata
- Download URL: graphitedb-0.1.1.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5cb8a5c554648d9eb6cc925d8cdde34477c48e06db9a88071379dc1fddb75c1c
|
|
| MD5 |
955a3ab5ad5a33ca68fd8910a3ccc3d4
|
|
| BLAKE2b-256 |
f271d1473c95d7448219cb37a21d6522c99165d49f9717e7391fd182177d127e
|
File details
Details for the file graphitedb-0.1.1-py3-none-any.whl.
File metadata
- Download URL: graphitedb-0.1.1-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bfd2b421471e0197e24218386abed9c186e4555d116759e877b9f2433e0ce6a4
|
|
| MD5 |
41ce312aaa7e7a2f3b6cc18771b6cf6d
|
|
| BLAKE2b-256 |
3430e5ba4b2fc495e5e7173d1810c665d6004ee99b8d58e499391decf3d056a5
|