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.6.12-cp313-cp313-win_amd64.whl (3.2 MB view details)

Uploaded CPython 3.13Windows x86-64

kglite-0.6.12-cp313-cp313-manylinux_2_35_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.35+ x86-64

kglite-0.6.12-cp313-cp313-macosx_11_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

kglite-0.6.12-cp313-cp313-macosx_10_12_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

kglite-0.6.12-cp312-cp312-win_amd64.whl (3.2 MB view details)

Uploaded CPython 3.12Windows x86-64

kglite-0.6.12-cp312-cp312-manylinux_2_35_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.35+ x86-64

kglite-0.6.12-cp312-cp312-macosx_11_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

kglite-0.6.12-cp312-cp312-macosx_10_12_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

kglite-0.6.12-cp311-cp311-win_amd64.whl (3.2 MB view details)

Uploaded CPython 3.11Windows x86-64

kglite-0.6.12-cp311-cp311-manylinux_2_35_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.35+ x86-64

kglite-0.6.12-cp311-cp311-macosx_11_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

kglite-0.6.12-cp311-cp311-macosx_10_12_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

kglite-0.6.12-cp310-cp310-win_amd64.whl (3.2 MB view details)

Uploaded CPython 3.10Windows x86-64

kglite-0.6.12-cp310-cp310-manylinux_2_35_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.35+ x86-64

kglite-0.6.12-cp310-cp310-macosx_11_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

kglite-0.6.12-cp310-cp310-macosx_10_12_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.10macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for kglite-0.6.12-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 4be448b5e902881629f246c434dd810a8db3b8d0253e22a3deb31a4eab32e73b
MD5 c828ecdb29056cd490c98cc887e6e1fd
BLAKE2b-256 ba0527512bfad0e928936717e7e50ea7f7744ae92f787e7f66662172af0a1b3d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.12-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 e7e3c8c83dba2b64b2269e945d0cfd411b6b149661123835e77ce1958c2b19d9
MD5 ca915fac56ffcb9b4df91a0d48e2a7ae
BLAKE2b-256 a4af8b8a3c35006bd88ae072d7b3308db951e6176743b78e93115d39d7fc5df9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.12-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c178abbca54233bd08847a3a5a5f4c4d38700accdcd409d231297a644ff3546a
MD5 780370fa34b372c73934564e57679b7b
BLAKE2b-256 f65c4e4c52636fe19293a61c1909c87bbadbb4d70bc0a0c2ddeb500b1e6a244e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.12-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 17a14c2a4486b741d70ac30491ea7d973b37f0ce8e99d01dd687a1520c1da446
MD5 2ae7b9e7be402ca61b032456a16d7089
BLAKE2b-256 abb99d07f812f81d05ceb32cacaf7f25ce6f3245b778574b3e028477be83c553

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for kglite-0.6.12-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 4a945bc2323a7f6b66efd8a22373ed4ea7dd69b06d85b9c6b6446155fd9d8dd9
MD5 c07af8ce3a1381b374f34c244033e82f
BLAKE2b-256 ccf75fd1cf5afd15eb06580c6f83b4eab07081713cf2c21ed63d4cc37d9a606c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.12-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 1d8ae10c99b5b79dec16be8cfcd585faa82b77031485696c936ffe48b8366a14
MD5 8a621ad82d0ef3f4fa8a7e4eebfc3b16
BLAKE2b-256 1c4d00196e3ea47ecfae0c4abddf7ca898fc5286e4d8cdf37a09713f5672edce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.12-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b12d18eeb207c9d017e492fdc474d178863916fc3cb361ee98ebe52e469f19dc
MD5 3b90050379f25b88e6757b4584d2e7ed
BLAKE2b-256 13c26167cf28345d90c76f1f03cbb83c1e496bf56abf4feac39f330435bfaf59

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.12-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 dc529021dcb7b11fbbd20f72169e50b58e171b597a7f4d5119a92824227f5d20
MD5 17a594b83dc305bbf15fe0f77839fdb5
BLAKE2b-256 5b515fed4a3286cea9c29b42aac0298303d1bc9aa599b1bf58a85036940a54cf

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for kglite-0.6.12-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 6b9d1428c8fc792e6e473ff2b0e93e505dc9335c49a6472a2508a3aa8e52fd8c
MD5 6135466b6ab6655fde76cbb96f31e583
BLAKE2b-256 51a1a4c8da6207647e2096968efe8320030583e7c0599d8d1a2405ef36130ee2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.12-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 4f0dc7090548cfbb55c9ecffef731a61bbd7ec46c751bdded9d729f6f9a6c7cb
MD5 c7c120bd082047e7d84c2fe880d82b78
BLAKE2b-256 6e573e71b9bc82851f517cd44abfdbedeadc4efadb5888eeb3a6a30025963fb1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.12-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b81b51566d029779c77d137f8a93519a99ee557787cf8cd1a84787b8c0b2ca24
MD5 5cbe499abd518a218b655665158b00c7
BLAKE2b-256 ad28664472ed66fec81b2ec028b3124e4e3fcbc9272e53b5127afed5cf92e5f3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.12-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 07b3cec6b55d1f15dee379bb0258b8968a9d8d9e538079afa2425258e894b0da
MD5 22b151ea4235c4055021c2c55ed4dfc4
BLAKE2b-256 f08e24e48567df08da2e1e9bd1076a13849488e84402f0ae379af070b9a71b8a

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for kglite-0.6.12-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 f78509477f0267c954ddad06e12943461be3123dc04bf2d8c71732b3f8e2c219
MD5 c280a816a06b5d6c48020cb5f74caedc
BLAKE2b-256 cf383b9cd00fa7055b2eadaddc5bb0ab72333f108ae8fcb73fa2eb3bfdd15d07

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.12-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 a7ac00a290d1a368976772567801a8f23513233362dc8a449460f69b9c2c1b33
MD5 7f140c57f335c17b1d87ef3e6b567acd
BLAKE2b-256 28bea58e857f788f2b747df983772b7d36ffe6d5ce0090d38b46726a0a50dcd5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.12-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d87edadd6b9b433070a0cd827b89f208bed3f1fb1594e3b15d443b7f75b742c7
MD5 7b7e08a00be06a57674c3812676d1a83
BLAKE2b-256 65b58ec80e9b5784ce360e1fc052cd1a16b8baa467c97eff899777e8b004a0c1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.12-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 05d6b0b482f25f2e5a6901f953d407fe08ec6d0bc6a85ee4a2ff4257b8dc4f98
MD5 3c231187eaa88a1c631dddf15c158bf5
BLAKE2b-256 08f537b12a55041985539547546ab89cbdd31237a7eeed2971ceb4151579dec3

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