Skip to main content

samyama — Python SDK for the Samyama Graph Database

Python bindings for Samyama, a property-graph database with a Cypher query engine. The extension module is built from Rust with PyO3 on top of crates/samyama-sdk, so the embedded mode runs the engine in-process — no server, no network.

Install

pip install samyama

Wheels are abi3 and work on CPython 3.8+.

The package also installs samyama_aio (asyncio wrapper), samyama_nb (notebook helpers) and samyama_mcp (an MCP server, entry point samyama-mcp-serve).

Connect

Two modes. Embedded runs the engine inside your process:

from samyama import SamyamaClient

client = SamyamaClient.embedded()

Remote talks to a running Samyama server over HTTP:

from samyama import SamyamaClient

client = SamyamaClient.connect(
    "http://localhost:8080",
    timeout_seconds=30.0,          # whole-request deadline
    connect_timeout_seconds=5.0,   # TCP connect only
    max_retries=2,
    retry_base_delay_ms=100,
)

A refused connection is retried for any request. A timeout is retried only for reads (query_readonly, query_stream, nlq, status): a write that times out raises samyama.RequestTimeoutError (a RuntimeError subclass) without being sent again, because the server may already have applied it.

Both return the same SamyamaClient, with the same query methods. Graph algorithms (page_rank, wcc, scc, bfs, dijkstra, pca, triangle_count) and the vector methods (create_vector_index, add_vector, vector_search) are embedded-only and raise RuntimeError on a remote client.

First query

from samyama import SamyamaClient

client = SamyamaClient.embedded()

client.query('CREATE (:Person {name: "Alice"})-[:KNOWS]->(:Person {name: "Bob"})')

result = client.query_readonly(
    "MATCH (a:Person)-[:KNOWS]->(b:Person) RETURN a.name, b.name"
)

print(result.columns)   # ['a.name', 'b.name']
for row in result.records:
    print(row)          # ['Alice', 'Bob']
print(len(result))      # 1

query is read-write, query_readonly is read-only. Both take an optional graph argument, which defaults to "default"; this build serves a single graph and rejects any other name.

A QueryResult exposes columns, records, nodes, edges, and len().

Other methods on the client: status() (returns a ServerStatus with status, version, nodes, edges), ping(), list_graphs(), delete_graph(graph="default").

Snapshots

A .sgsnap file is a whole graph in one file. In embedded mode the client loads and saves one itself, so a notebook, an evaluation harness or an agent needs no server and no network:

from samyama import SamyamaClient

client = SamyamaClient.open_snapshot("pubmed.sgsnap")   # embedded, ready to query
client.query_readonly("MATCH (a:Article) RETURN count(a) AS n")

client.query('CREATE (:Note {text: "checked"})')
report = client.export_snapshot("pubmed-annotated.sgsnap")
print(report["nodes_exported"], report["bytes_written"], report["dropped"])

import_snapshot(path) adds a snapshot to a client's graph and returns a report with the keys of the server's import response (nodes_imported, edges_imported, nodes_merged, merges_by_key, dedup_keys_unused, ...) plus duration_ms. Pass dedup_keys=["drugbank_id"] to merge incoming nodes into existing ones that share a key value; open_snapshot takes the same argument. export_snapshot replaces any file at path, and its dropped list says what the format does not carry.

Vectors added with add_vector are not carried. add_vector puts a vector in the vector index only, not on the node as a property, and a snapshot holds node properties and index declarations. After open_snapshot the index exists but is empty, and vector_search returns nothing; the export's dropped list does not report it yet. Re-add the vectors after opening.

All three are embedded-only: a remote client raises RuntimeError, because a server imports and exports its own snapshots (POST /api/snapshot/import and POST /api/snapshot/export). A file that is missing or is not a snapshot raises RuntimeError and leaves the graph unchanged.

asyncio

samyama_aio wraps the same client, running each call on a worker thread so the event loop is not blocked:

import asyncio
from samyama_aio import AsyncSamyamaClient

async def main():
    client = await AsyncSamyamaClient.embedded()
    await client.query('CREATE (:Person {name: "Alice"})')
    result = await client.query_readonly("MATCH (n:Person) RETURN n.name")
    print(result.records)   # [['Alice']]

asyncio.run(main())

AsyncSamyamaClient.connect(url, **kwargs) takes the same keyword arguments as SamyamaClient.connect.

Natural-language queries

nlq turns a question into Cypher. It returns the query and does not run it; a generated query that writes is refused.

client = SamyamaClient.embedded()
# ... load a graph ...
cypher = client.nlq("Who does Alice know?", provider="openai")  # key from OPENAI_API_KEY
result = client.query_readonly(cypher)

In embedded mode the translation happens in this process: the model is shown this graph's schema, as the server would show it. The provider is read from the same environment variables the server reads, and the keyword arguments take their place for one call:

argument environment variable it replaces
provider NLQ_PROVIDER — openai, gemini, ollama, claudecode or mock; no default
model NLQ_MODEL (default gpt-4o)
api_key the provider's own: OPENAI_API_KEY, GEMINI_API_KEY
api_base_url NLQ_API_BASE_URL

No server is involved, but the provider still is: openai and gemini send the question and the schema summary to that service. mock answers a fixed query without leaving the process, for tests.

A remote client asks the server (POST /api/nlq), which chooses its own provider, so passing any of these arguments to it raises ValueError.

More

Apache-2.0.

Metadata

Release files for samyama 1.17.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for samyama 1.17.0
File Size Uploaded Provenance Actions
samyama-1.17.0.tar.gz 7.6 MB With provenance Details for samyama-1.17.0.tar.gz

Release files / samyama-1.17.0.tar.gz

Download URL samyama-1.17.0.tar.gz
Size 7.6 MB
Tags Source
SHA-256 checksum
How to use checksums
3f6945857ad5303c0f8c5299c05f9d3e452a88e688faa882faf7f8c441fa2a2c
BLAKE2b-256 checksum
How to use checksums
50639bcaaf5e960f6def92ab4cb96ad871a23ae034e63f27098062536b8f5e81
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Security for samyama 1.17.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

1 file in this release has been uploaded with provenance metadata.

Attestation for samyama-1.17.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page