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

Uploaded CPython 3.13Windows x86-64

kglite-0.6.6-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.6-cp313-cp313-macosx_11_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 10.12+ x86-64

kglite-0.6.6-cp312-cp312-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.12Windows x86-64

kglite-0.6.6-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.6-cp312-cp312-macosx_11_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.12macOS 10.12+ x86-64

kglite-0.6.6-cp311-cp311-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.11Windows x86-64

kglite-0.6.6-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.6-cp311-cp311-macosx_11_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

kglite-0.6.6-cp311-cp311-macosx_10_12_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

kglite-0.6.6-cp310-cp310-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.10Windows x86-64

kglite-0.6.6-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.6-cp310-cp310-macosx_11_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

kglite-0.6.6-cp310-cp310-macosx_10_12_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.10macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: kglite-0.6.6-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 3.1 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.6-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 291de7310fd93150f50a96f190d633bf3675177acfec777b4175a1580a2e1cae
MD5 bec357da9e1dad60605f419ada4e4e92
BLAKE2b-256 096a3b2680f486d31bd812328f31def216337e1e14dbe153da105b32537ff51f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.6-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 929e455b9166e4d1481316941dc69f932ae7c85519dcb55a80cff41b2a7528e9
MD5 f2bd6ef043d3cd01b3dc2a8125b4dbc5
BLAKE2b-256 fa307f3fe17d9f0fd74c4f6431242650ad9d212ed219e67a6998e4f365b03912

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.6-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 20c7dcafd3503a1575d70f57c483640d1b2a056be207276b20e33e456a1cbeec
MD5 3876c4b6943e709849fedd7921c3d2dc
BLAKE2b-256 41dd79376cd77ace20fccafdfb2fddc3f474a638f2c4496982915dd16c468fbe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.6-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 cc56b7f72428314d938123034be32b04765ae90b11c4e517f794f179d347b5a8
MD5 47bbc38d22158d2addac51fed4dbb543
BLAKE2b-256 cc583e17cc46af03cf2804df0eb529468856bf1c27c965c0c3dcbabcc3764178

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.6.6-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 3.1 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.6-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 7d86b571fcbf2eff2c651f1f45eec82a6bd0686858685d36864e37c7258dc41f
MD5 1f58495025e5eb585fefbd69fabf7001
BLAKE2b-256 627fc0c6925d7718c95d9ea67772fdedb7725a23ddd36dc1f54b782ba731a555

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.6-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 8a5df6682e9118481e2a15017dbac1df7caff4928ada236863793bfc22f5688c
MD5 ec6da8f37d375ce4d63e1c2d0cecb7b5
BLAKE2b-256 1b7c876d6f5ed31e87e44f7172d77e85710307843e888e49279b20fd5669e9c7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.6-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cff6c0c86ac2adc4f5be59662baa14e3dc5e9b8fab9bf2896a32d97795088e81
MD5 0352572fd4c7a393708fc9665eb2fc10
BLAKE2b-256 16bb254dd4fd25a233984ee7a4040079e2473f847d724b3425c2aa39ac4b2e9d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.6-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 78caf795fe29747654e7ecf98275d305c61bbdb58f984852ee96a699d5960f8c
MD5 3ec1ca4d3d13c9226d39ab8f97a9bcdd
BLAKE2b-256 4172b3eb95ed5693db2d43534e0dffd450cf4c67029bc21577abbc01dfda29aa

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.6.6-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 3.1 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.6-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 06ac5bf5471896eda46eda3f814865dcad58a64baf8415d7e03e7aba34477317
MD5 97192d2def99a11a51fd87bf0ea37934
BLAKE2b-256 a475522e5f458015c9fbba0939fab08e52779b9190bc0ca305989423c6fd0173

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.6-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 124b9d395721469734f4d8b30c9b4152f175b2762c62e45ca756280844e09f31
MD5 796be865d982d97f2b07b99b581e80ef
BLAKE2b-256 8f5171ccf6ab1071fa9b411bb0c3b9aa09ba2a4763cbbdfa45d736a7f560d569

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.6-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 47aea8f65725aa5bdce57e9ce6e9899f67cd37be6735769453ddfe3e6d626383
MD5 0a12c3c3406931ecac4bc6203b12d581
BLAKE2b-256 6a5f166ea86b24f98bfda593452f234427cffebde65aead644d4a9871e89ca8b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.6-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 056ff486ea6e348a541301c808795ef89125b7b5d984e4ca71f573db3f5c78dc
MD5 5900f89002eef9880a2aff9ded784553
BLAKE2b-256 1bcdf87b8c33e3e9f8acda78b1ce15688f63b49e12a940f4a41c8af199d063de

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.6.6-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 3.1 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.6-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 e7b05dec8b34b8f3a8c09af29231338a1ef83d31c6c1cfeb5b4064f20641ed97
MD5 ddcfce0b09877d1c816fd0861ff00a0d
BLAKE2b-256 5851a2a3785ca1de6c685562f21af1d1d222a60b822c3711da03e9517c1b6db7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.6-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 00aef050001cefb58cc13ab7c762b7270ecc9147c35233ad917bc8026eaa246e
MD5 41ff9d0e73ffe2b940f8cec145e5fd99
BLAKE2b-256 b6116ee0fd61b6e8b40656e9df30e1706dbbfbf1fcb1845f05deb3a9c71758e0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.6-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 748475e8681246d423ee95c41673d916991357758347cdfd2c350439aa738320
MD5 036ee6510305a0633f6e1d25f3fc8193
BLAKE2b-256 de6d022bd7b47f2069535635cd408a7b6dbfe82a162a8db1ab9bc45b6d116607

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.6-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 0bab1927d76b3c8e33e9a6d7762887b5b129b26e9e64037eab10b49946d3d127
MD5 068dbffd70f0faea3475019719e0c064
BLAKE2b-256 fc4a73148837d66d5f00023ffd0f9e581ea1eb329022110142f54448809057af

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