Your first query
This page builds the same two-person graph three ways. Each one uses an
in-memory namespace (memory://), so nothing is written to disk and there
is nothing to clean up. Swap the URI for file://… or s3://… when you
want the data to persist — see Storage URIs.
pip install namidbimport namidb
db = namidb.Client("memory://demo")
db.cypher("CREATE (:Person {name: 'Alice', age: 30})")db.cypher("CREATE (:Person {name: 'Bob', age: 25})")db.cypher(""" MATCH (a:Person {name: 'Alice'}), (b:Person {name: 'Bob'}) CREATE (a)-[:KNOWS {since: 2020}]->(b)""")
rows = db.cypher( "MATCH (p:Person) WHERE p.age >= $min " "RETURN p.name AS name, p.age AS age ORDER BY name", params={"min": 18},).rows()print(rows)# [{'name': 'Alice', 'age': 30}, {'name': 'Bob', 'age': 25}]
friends = db.cypher( "MATCH (a:Person)-[k:KNOWS]->(b:Person) " "RETURN a.name AS a, b.name AS b, k.since AS since").rows()print(friends)# [{'a': 'Alice', 'b': 'Bob', 'since': 2020}]Each write is durable when cypher() returns. Any result converts to a
DataFrame with .to_pandas(), .to_polars() or .to_arrow().
Without --store, namidb run uses a throwaway in-memory namespace, so
build and query the graph in one script. Statements separated by ; run in
order against the same namespace:
namidb run " CREATE (:Person {name: 'Alice', age: 30}); CREATE (:Person {name: 'Bob', age: 25}); MATCH (a:Person {name: 'Alice'}), (b:Person {name: 'Bob'}) CREATE (a)-[:KNOWS {since: 2020}]->(b); MATCH (a:Person)-[k:KNOWS]->(b) RETURN a.name, b.name, k.since"Each statement is announced with a == statement i/n header; the last one
prints:
== statement 4/4a.name | b.name | k.since----------------------------"Alice" | "Bob" | 2020To keep the graph between invocations, point --store at a directory:
namidb run --store "file:///tmp/namidb-demo?ns=demo" \ "CREATE (:Person {name: 'Alice', age: 30})"namidb run --store "file:///tmp/namidb-demo?ns=demo" \ "MATCH (p:Person) RETURN p.name AS name"Start a server on an in-memory namespace (Docker shown; the release binary takes the same flags):
export NAMIDB_AUTH_TOKEN="$(openssl rand -hex 32)"docker run --rm -p 127.0.0.1:8080:8080 -e NAMIDB_AUTH_TOKEN \ namidb/namidb-server:3.3.0 --store memory://demoIn another shell, with the same NAMIDB_AUTH_TOKEN:
q() { curl -s localhost:8080/v0/cypher \ -H "Authorization: Bearer $NAMIDB_AUTH_TOKEN" \ -H 'Content-Type: application/json' -d "$1"; echo}
q '{"query": "CREATE (:Person {name: \"Alice\", age: 30})"}'q '{"query": "CREATE (:Person {name: \"Bob\", age: 25})"}'q '{"query": "MATCH (a:Person {name: \"Alice\"}), (b:Person {name: \"Bob\"}) CREATE (a)-[:KNOWS {since: 2020}]->(b)"}'q '{"query": "MATCH (p:Person) WHERE p.age >= $min RETURN p.name AS name, p.age AS age ORDER BY name", "params": {"min": 18}}'The last call returns:
{"columns":["name","age"],"rows":[{"age":30,"name":"Alice"},{"age":25,"name":"Bob"}]}columns carries the RETURN order; each row is a JSON object. Write
statements also return a write_outcome with counters.
Next steps
- Reading data and Writing data
- Embedded Python for durable stores, bulk loads and read-only clients
- HTTP server for production settings