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

Uploaded CPython 3.13Windows x86-64

kglite-0.7.16-cp313-cp313-manylinux_2_35_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.35+ x86-64

kglite-0.7.16-cp313-cp313-macosx_11_0_arm64.whl (3.3 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

kglite-0.7.16-cp313-cp313-macosx_10_12_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

kglite-0.7.16-cp312-cp312-win_amd64.whl (3.7 MB view details)

Uploaded CPython 3.12Windows x86-64

kglite-0.7.16-cp312-cp312-manylinux_2_35_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.35+ x86-64

kglite-0.7.16-cp312-cp312-macosx_11_0_arm64.whl (3.3 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

kglite-0.7.16-cp312-cp312-macosx_10_12_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

kglite-0.7.16-cp311-cp311-win_amd64.whl (3.7 MB view details)

Uploaded CPython 3.11Windows x86-64

kglite-0.7.16-cp311-cp311-manylinux_2_35_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.35+ x86-64

kglite-0.7.16-cp311-cp311-macosx_11_0_arm64.whl (3.3 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

kglite-0.7.16-cp311-cp311-macosx_10_12_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

kglite-0.7.16-cp310-cp310-win_amd64.whl (3.7 MB view details)

Uploaded CPython 3.10Windows x86-64

kglite-0.7.16-cp310-cp310-manylinux_2_35_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.35+ x86-64

kglite-0.7.16-cp310-cp310-macosx_11_0_arm64.whl (3.3 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

kglite-0.7.16-cp310-cp310-macosx_10_12_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.10macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: kglite-0.7.16-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 3.7 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.16-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 891bc903ef34bd407f07e189d157a2353f92d6cee826f74568f0c1966440a13c
MD5 56841a04f698ec47e9009f8c6522e76b
BLAKE2b-256 52c9e392bcb64b7edcf7b12051a506002155e526b324275f0c44dd89f64beffa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.16-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 c8d45b53fe24b50c84bd02e0d673608f56b33ee24967fa715faa8cdedc1d05a2
MD5 37d14882fb2ee0a7cd1bf0511c66e7fa
BLAKE2b-256 0284836600ccac9d8d8e0e35e5774e8dd1a7eeb195f4193fae8a5e83d8117fbf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.16-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 241f97db8948b7a1846bb15d959366092930549b4e029c9958d56d4ff2c09c57
MD5 0222faf91e8a233ec44dd587afe8ffc4
BLAKE2b-256 1c5a5af772b06cfcc9ed92450f66a6d97739bc03b0253477b4ed5765aa6d640d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.16-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 6bbd30dc53fcfc9f7af91cff38bf5049b167eafca02845b00334e5ed4b375a59
MD5 e91710ab1b3dfec10589e7f5d7092ddf
BLAKE2b-256 df523ada09d8401ed614b202fa71fd447366161bd9c4b5e12a7ebcb24b6d900e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.7.16-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 3.7 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.16-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 757c3a9e759644c7ac493593f9baef20e361057869ff40bfe7b9a2029e8560af
MD5 5c2fefec7c917e837d8c4e8a291af9dc
BLAKE2b-256 36d7f1eb1c712e221d9c8597873251bf830da5a8bc6e1eaa54c40cd7a33876c7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.16-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 cda55ba59a07925f3e56b61dc845657f6bb175e18c0a7f3150285d892fbf8bd3
MD5 0db0905364e0c87d74ff9c9095c7afb7
BLAKE2b-256 7eb10be130f6ed413c8ee495a0b99c7c8cc944158a340faa16faca02a4678e86

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.16-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 be0ad3a3ae2ca870a7043e91528b659a9bd1804f7ceaca61863a00347ae4346f
MD5 bdfe48a299c1dad0c98ab365ab3df027
BLAKE2b-256 571bb73dc21bb5475dd05ee3c1fba851128c68c316004b15c125f705b1110838

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.16-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 2c8b17e1ac8c456856eb1d03305cdf2eae92062e2dcab66443070a7abd964fbd
MD5 b609b755af4421c544d845e4ec4073c0
BLAKE2b-256 9f6a87365043fda2047af118d076af9953f2af77115f0c3b94f45440eabe8168

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.7.16-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 3.7 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.16-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 e3395ca2836f913078695152f156b2ef5a8fd3617d086c39dbb50dcd4dc6924f
MD5 0f8b8687d5d26f6a61ad5a7b038a6331
BLAKE2b-256 1c339d015fb02a2c78a427fbc82425fa7976ebe699221a1f441e07f96b85ddb2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.16-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 c043f45563e96a7e78d705e980ebde8bffd6438fae277707f980a6f708bab151
MD5 1a455a4f383ecf70b1f7c0a33f21a42d
BLAKE2b-256 6eaf2cfee34a83ac380a1f6cd516af5cca76a394f7b4d70e1af0af38416b017b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.16-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 229033bbdccf927faa126ab2e07fcaba9316d3fee12018377ed06257c7dca47f
MD5 478af4559d0c28caf27c3182ed6d9db9
BLAKE2b-256 2450b32ec5b00cf2d5f5d5c65a2fd69a757214d3cb6ac4d9167acf21cfa97ff2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.16-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ab3dd4f1a19ed1efd5acc66d90cb9fe3fb94f6810a442fa80b670b5fb40f0f88
MD5 b74e95822732f125cabe1ef8ce6b7ffe
BLAKE2b-256 d27b3bd1eadcc8d2964d9f6b615e5d67c101635872eb653b662e86de2e443676

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.7.16-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 3.7 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.16-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 8f6ae9b23d80c585d9a8f92a9dd2a62e57dd5f9036004de03ed610750b847c8e
MD5 b5c89e44624a3bdaa28378bc638003b3
BLAKE2b-256 989ebc7fb14b77903aaffe6ed27a6ebfb5adbd6dc1c8883989685d134fdcdf08

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.16-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 041794b5f8f045a87b66d2988b0aedfca458b5222bba56478829e6bd46e72538
MD5 56224b44e780912f5a2352e20490c484
BLAKE2b-256 4824e8078dfe4faf37eba7ecbef055a2ab2626d89adeccd4ede738413e959ed7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.16-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ca2f02740db231cc55173759a2086b8b31ff077252cd96ee5766e0aa59154739
MD5 da458ed2d00abec9170c21806d26d861
BLAKE2b-256 268de28ca471a533b25127e4e57a74740651c7f74d83d86f88a7a2f1ce2c63b1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.16-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 af3085b37af21ca2f677381f74d21426576f4db9cf5fc3e3c4105b76ac09c95f
MD5 451b1a72f66c5d7dba95e3c623c280ff
BLAKE2b-256 80601c23da1202bb23b55c9e6976ce66c2a269a58dab5aef10f31c25be10425c

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