Skip to main content

A high-performance graph database library with Python bindings written in Rust

Project description

KGLite — Lightweight Knowledge Graph for Python

PyPI version Python versions License: MIT Docs

An embedded, in-memory knowledge graph database for Python — built in Rust for speed, with a Cypher query engine, semantic search, and first-class support for RAG pipelines and AI agents. No server, no setup, no infrastructure. Just pip install kglite and go.

Why KGLite?

  • Zero infrastructure — runs inside your Python process. No database server to install, configure, or maintain.
  • Fast — Rust core (via PyO3 + petgraph) with zero-copy where possible. Load millions of nodes without leaving Python.
  • Query with Cypher — familiar graph query language for pattern matching, mutations, aggregations, and traversals.
  • Built for AI — semantic search with text_score(), schema introspection via describe(), and a ready-made MCP server for LLM tool use.
  • DataFrames in, DataFrames out — bulk-load from pandas, query results as DataFrames. Fits naturally into data science workflows.

Quick Start

pip install kglite
import kglite

graph = kglite.KnowledgeGraph()

# Create nodes and relationships
graph.cypher("CREATE (:Person {name: 'Alice', age: 28, city: 'Oslo'})")
graph.cypher("CREATE (:Person {name: 'Bob', age: 35, city: 'Bergen'})")
graph.cypher("""
    MATCH (a:Person {name: 'Alice'}), (b:Person {name: 'Bob'})
    CREATE (a)-[:KNOWS]->(b)
""")

# Query — returns a ResultView (lazy; data stays in Rust until accessed)
result = graph.cypher("""
    MATCH (p:Person) WHERE p.age > 30
    RETURN p.name AS name, p.city AS city
    ORDER BY p.age DESC
""")
for row in result:
    print(row['name'], row['city'])

# Or get a pandas DataFrame
df = graph.cypher("MATCH (p:Person) RETURN p.name, p.age ORDER BY p.age", to_df=True)

# Persist to disk and reload
graph.save("my_graph.kgl")
loaded = kglite.load("my_graph.kgl")

Use Cases

RAG & Retrieval Pipelines

Store documents, chunks, and entities as a knowledge graph. Use text_score() for semantic similarity search and Cypher for structured retrieval — combine both for hybrid RAG.

graph.cypher("""
    MATCH (c:Chunk)
    RETURN c.text, text_score(c.embedding, $query_vec) AS score
    ORDER BY score DESC LIMIT 5
""", params={"query_vec": query_embedding})

AI Agent Memory & Tool Use

Give LLM agents a structured, queryable memory. describe() generates a progressive-disclosure schema that agents can reason over, and the included MCP server exposes the graph as a tool.

xml = graph.describe()  # schema for agent context
prompt = f"You have a knowledge graph:\n{xml}\nAnswer using graph.cypher()."

Data Exploration & Analysis

Load CSVs or DataFrames, explore relationships, run graph algorithms (shortest path, centrality, community detection), and export results — all without leaving your notebook.

graph.add_nodes(data=users_df, node_type='User', unique_id_field='user_id', node_title_field='name')
graph.cypher("MATCH path = shortestPath((a:User {name:'Alice'})-[*]-(b:User {name:'Eve'})) RETURN path")

Codebase Analysis

Parse Python and Rust codebases into a knowledge graph with functions, classes, calls, and imports. Search, trace dependencies, and review code structure.

from kglite.code_tree import build
graph = build(".")
graph.cypher("MATCH (f:Function) RETURN f.name, f.file ORDER BY f.name")

Key Features

Feature Description
Cypher queries MATCH, CREATE, SET, DELETE, MERGE, aggregations, ORDER BY, LIMIT, SKIP
Semantic search Vector embeddings + text_score() for similarity ranking
Graph algorithms Shortest path, centrality, community detection, clustering
Spatial Coordinates, WKT geometry, distance and containment queries
Timeseries Time-indexed data with ts_*() Cypher functions
Bulk loading Fluent API (add_nodes / add_connections) for DataFrames
Blueprints Declarative CSV-to-graph loading via JSON config
Import/Export Save/load snapshots, GraphML, CSV export
AI integration describe() introspection, MCP server, agent prompts
Code analysis Parse codebases via tree-sitter (kglite.code_tree)

Documentation

Full docs at kglite.readthedocs.io:

Requirements

Python 3.10+ (CPython) | macOS (ARM/Intel), Linux (x86_64/aarch64), Windows (x86_64) | pandas >= 1.5

License

MIT — see LICENSE for details.

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

kglite-0.7.6-cp313-cp313-win_amd64.whl (3.6 MB view details)

Uploaded CPython 3.13Windows x86-64

kglite-0.7.6-cp313-cp313-manylinux_2_35_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.35+ x86-64

kglite-0.7.6-cp313-cp313-macosx_11_0_arm64.whl (3.2 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

kglite-0.7.6-cp313-cp313-macosx_10_12_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

kglite-0.7.6-cp312-cp312-win_amd64.whl (3.6 MB view details)

Uploaded CPython 3.12Windows x86-64

kglite-0.7.6-cp312-cp312-manylinux_2_35_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.35+ x86-64

kglite-0.7.6-cp312-cp312-macosx_11_0_arm64.whl (3.2 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

kglite-0.7.6-cp312-cp312-macosx_10_12_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

kglite-0.7.6-cp311-cp311-win_amd64.whl (3.6 MB view details)

Uploaded CPython 3.11Windows x86-64

kglite-0.7.6-cp311-cp311-manylinux_2_35_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.35+ x86-64

kglite-0.7.6-cp311-cp311-macosx_11_0_arm64.whl (3.2 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

kglite-0.7.6-cp311-cp311-macosx_10_12_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

kglite-0.7.6-cp310-cp310-win_amd64.whl (3.6 MB view details)

Uploaded CPython 3.10Windows x86-64

kglite-0.7.6-cp310-cp310-manylinux_2_35_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.35+ x86-64

kglite-0.7.6-cp310-cp310-macosx_11_0_arm64.whl (3.2 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

kglite-0.7.6-cp310-cp310-macosx_10_12_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.10macOS 10.12+ x86-64

File details

Details for the file kglite-0.7.6-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: kglite-0.7.6-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 3.6 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for kglite-0.7.6-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 3f73d07dee003c3c4b114ba06bd73e1c4abbe9aa97178a17f5562f559fb6a39d
MD5 a7588bc88a5152be99e37005672c6254
BLAKE2b-256 d58a32855b2c632354ae3bc468d436890be79d6af337e92f4308d06a4f86da0a

See more details on using hashes here.

File details

Details for the file kglite-0.7.6-cp313-cp313-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for kglite-0.7.6-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 8ae5190080b640f05be793a70b4e52d9d8b48cfe12da7202bd0e5a1aabd2b2d4
MD5 4e3224ff53b40fa14b0c789fa9929448
BLAKE2b-256 5f7a849bca1f998da1b52d13fbe41f16a812d455ee8e658ed6974af67e9fb80f

See more details on using hashes here.

File details

Details for the file kglite-0.7.6-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for kglite-0.7.6-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c5b4cfe66fbd3b33cacef7b85af7d97cb00021d95033e64672db2dffba7a9322
MD5 1102e1507f0c17da9bca707f5315350f
BLAKE2b-256 6c3fe31c68846543c221c6108ad364e4ccd2d85e18456cfc461d6a30d86c2167

See more details on using hashes here.

File details

Details for the file kglite-0.7.6-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for kglite-0.7.6-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 38e774f9a2ff37efcfd5aec11b9b1cef3499a4bfab98ddaa9a98e27a48c5482b
MD5 cdc84cb1d4ccc23e9b0e054634fa4091
BLAKE2b-256 f48f61a507d2d107de78c9667078daf5a4371b1efee78c502d122cff77c7cf1f

See more details on using hashes here.

File details

Details for the file kglite-0.7.6-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: kglite-0.7.6-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 3.6 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for kglite-0.7.6-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 03c1726ecd83efeceed8b698c1f86dffd163b0bbe504a35e54ca163b79b31e85
MD5 fc280eb3035ddeb76b2695013c114f4a
BLAKE2b-256 1b93b6f9f9969a5dcc227c723c288381f341188e5e933f4c2b092da2562e7151

See more details on using hashes here.

File details

Details for the file kglite-0.7.6-cp312-cp312-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for kglite-0.7.6-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 7a9e03225deca0fbd4688a087ddeb2f2abdb4d5128aba36f3e99d44038e011c0
MD5 c458162546b52eacd57ae1e707745a1a
BLAKE2b-256 fd620dd695ef1c9a5b787fb3ebe694a9dd1b845365712440305ac3c88f8cd3b3

See more details on using hashes here.

File details

Details for the file kglite-0.7.6-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for kglite-0.7.6-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8ff7cf111a500cd2e434f7e71050bacc491c9d652acd787e620b5c9ad7a8223a
MD5 1228fb7e1e53bb487b12e6b0e8bce585
BLAKE2b-256 48e32d568fd230fc7e738019139a79a55564969fe9a787bb0f85072430f405af

See more details on using hashes here.

File details

Details for the file kglite-0.7.6-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for kglite-0.7.6-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 0c8d40f596bc42adc3a6afec2d752d8bcd1e83771d68a9104bdd56dfbfebd0d4
MD5 a1a36c85b4ab34a850545e50564ed868
BLAKE2b-256 d663d2fd0fd6c773153386d8e7b630b480d30f5cb8c0db0f57d1cf66dff9ec4b

See more details on using hashes here.

File details

Details for the file kglite-0.7.6-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: kglite-0.7.6-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 3.6 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for kglite-0.7.6-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 e5cfccf0ba4927705db3d90019a84d10b5b30d2eed07b1cf951519d5a65e1fe4
MD5 62f180e63c4672063e444e971e8abd9c
BLAKE2b-256 572ccd1003b3f5b75c5e4cb3ad0fade862ed6d414904fc66f71632f6a0b0145b

See more details on using hashes here.

File details

Details for the file kglite-0.7.6-cp311-cp311-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for kglite-0.7.6-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 d7ab37d9e1c167462f0e7dbcee18b2e5ef9203cd5590a9f422f6634178743c17
MD5 521c494ea55cfc54f38939b29c20724a
BLAKE2b-256 2fc1db832206c94d328436ab9f6b3d07967450b388dbac4e5fd7256aa7bd4eb6

See more details on using hashes here.

File details

Details for the file kglite-0.7.6-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for kglite-0.7.6-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fcf280573cd8e94365e39c42ae1b0ba1022fdcfb4c23d384b4ea19f511d9575c
MD5 2d44605d9aef497d388ce688891d9dff
BLAKE2b-256 cf788274fc1f457731f79537345cc71d4a704d78ae7881626fbaa8a2d70f507a

See more details on using hashes here.

File details

Details for the file kglite-0.7.6-cp311-cp311-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for kglite-0.7.6-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 5f875c0eccdf41c54214cb26861a9f3e617762a4eda5a0a767928613daa7be5c
MD5 e1fe09ebf49f44a8ce6a5fabccdf8fff
BLAKE2b-256 328ad7d8159c47ef438f47753d1b289261349be0b64692c60110d027e53aacb0

See more details on using hashes here.

File details

Details for the file kglite-0.7.6-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: kglite-0.7.6-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 3.6 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for kglite-0.7.6-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 db29d9560efb604f3308a519d0d74c695f69e338804e063c8528985a6b21ded9
MD5 fa666293ce6fb78bb6911ed1c11fc1fd
BLAKE2b-256 4bbc017c1c10b66c88d356c3cf59e24bc67bc155073f71aae9776a201e3352eb

See more details on using hashes here.

File details

Details for the file kglite-0.7.6-cp310-cp310-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for kglite-0.7.6-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 73153feabd64ecfd6aca1befbbaabd76d7251d147373c83f9d8fa80e007a44a9
MD5 7fccf722f6f86a4d39a3c343e0685573
BLAKE2b-256 42ede97e451925c5bf01a67c62772e726f1c78e2b4be8f24b9b63af127e5fb47

See more details on using hashes here.

File details

Details for the file kglite-0.7.6-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for kglite-0.7.6-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f3f89c07396f6244417419353eed05de26b526d5a84bfc3f62114a49e575f90e
MD5 4f66c85c79fb1081d06678e9980f9486
BLAKE2b-256 447ce74905274876e21c8965c846f1fbb7cb0b8a22bd4b1742bc7b59d382446c

See more details on using hashes here.

File details

Details for the file kglite-0.7.6-cp310-cp310-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for kglite-0.7.6-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 94252910ba712944209bd3631e0ce9d219b2a699a81ca67324948cc705ba0d15
MD5 a79f723c78c0f675c9e43ef34f15f5f3
BLAKE2b-256 fabaf6cc6a131af4946e491d45feca927398bcac03768dc764ac5ff5c8d787f3

See more details on using hashes here.

Supported by

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