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

This version

0.7.0

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

Uploaded CPython 3.13Windows x86-64

kglite-0.7.0-cp313-cp313-manylinux_2_35_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.35+ x86-64

kglite-0.7.0-cp313-cp313-macosx_11_0_arm64.whl (3.0 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

kglite-0.7.0-cp313-cp313-macosx_10_12_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

kglite-0.7.0-cp312-cp312-win_amd64.whl (3.4 MB view details)

Uploaded CPython 3.12Windows x86-64

kglite-0.7.0-cp312-cp312-manylinux_2_35_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.35+ x86-64

kglite-0.7.0-cp312-cp312-macosx_11_0_arm64.whl (3.0 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

kglite-0.7.0-cp312-cp312-macosx_10_12_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

kglite-0.7.0-cp311-cp311-win_amd64.whl (3.4 MB view details)

Uploaded CPython 3.11Windows x86-64

kglite-0.7.0-cp311-cp311-manylinux_2_35_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.35+ x86-64

kglite-0.7.0-cp311-cp311-macosx_11_0_arm64.whl (3.0 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

kglite-0.7.0-cp311-cp311-macosx_10_12_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

kglite-0.7.0-cp310-cp310-win_amd64.whl (3.4 MB view details)

Uploaded CPython 3.10Windows x86-64

kglite-0.7.0-cp310-cp310-manylinux_2_35_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.35+ x86-64

kglite-0.7.0-cp310-cp310-macosx_11_0_arm64.whl (3.0 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

kglite-0.7.0-cp310-cp310-macosx_10_12_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.10macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: kglite-0.7.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 3.4 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.7.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 ee10c8861b0a0a1954484081d71bc8d3d07c92a2bcd75f26a5cf6a93cc2c63d6
MD5 67cec4892d57646605559e940ea6e0d0
BLAKE2b-256 c426c820eeca17d60f0c8bbfab2ca7a221fd091ef70bda88b0996834313e4f03

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.0-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 f115d0be3900385778c278476c0c925d12d6f466bb3dce92a63cd90be001d114
MD5 b22ba9b52f6a9e09e7537e7db9569bec
BLAKE2b-256 d0d4576a0045860c99b652f3639726bbe315026b47c4c7fd014c72108bf94c57

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 983a9948d70b81bf290618ec8e4a8b1f01d06c5e467e622a937ec633f5231ffb
MD5 e338e04c77f195fb9d628f1b21208251
BLAKE2b-256 c983cd606213f531a8fa33e1f404a2a2ee15186e76a5884364af40baea2e76ff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.0-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 fd88011f673d533fd67c17305c74da2a00f296d399fe52eea2a7b284efd5695e
MD5 f6dd7f76a44049a676705036611dc22e
BLAKE2b-256 12231b93ee23ecfacdce12d03d274dd83b01a34b3119c9af7f68c2b2e3feb1e6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.7.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 3.4 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.7.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 6a632e28585c1ccfdd6304a3921aa5fd692adb0ab3dd584e002990bb114ed870
MD5 1c4428ba8fc68b8e1126519def340c22
BLAKE2b-256 55fa8677191a6990923101cb6d040a80e84d4e639a0401005e765c84eb5c9df8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.0-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 824e76eb772e256fb4d740f8a3a560a2942b9bd7c234a2f3028ab6a220185cc3
MD5 a87dae8dadfe44b56bba74bce272d603
BLAKE2b-256 b97ac49f7534100143f09c4436c147e47c6da005bbfb1b759004fecb000c240e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a25d3a9c430bec1fd2a3f8b583c79d2aec3da1010a05104f69bf4a0a0f16b1f6
MD5 df016cebeddaacd2755c8188d604374f
BLAKE2b-256 aa4c635f827f23bc4ea69a37d355026b846b5216919c00af197fef7c3d659173

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.0-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 c34f2485f19871ad4645ceb2cfaa77649979f4acd943fc146148562352d03d67
MD5 84e605c977bb60069de82f136864f1d4
BLAKE2b-256 ca39dbd32626ca0abaa5df28bec2d02ac88e6cdc847b39e83ce11bfd49e57151

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.7.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 3.4 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.7.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 8c31d3ac1cb5b6af4413a77d796d8ff5cb3d96efe39f99dee76e8f3267246c73
MD5 f0e42756afc7896ab4c1f1a3fe017df4
BLAKE2b-256 4a3bcc524f29fd5af4ce8923ca2050eec6254ce099522e25e70cc5a0be406062

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.0-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 b1bb29354cbd28f9ba96ecb7303917c960ebc7c7b40c3cdddf70aca3b8b9bfa2
MD5 8d03242697253452c7fb327ed6aa86e7
BLAKE2b-256 285cf56687f81d1b570507c95bf4822d787cf5f2a8f4735d96e144bebc621241

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 12fddfb0cd54637b6dacf20f56408dc9d9932072fe1f74d971b459784f8d3d2c
MD5 93ee7c8c064de13ae0bce6bca4434da7
BLAKE2b-256 cada4d92ebbe6d387eac7c4c458aed8d2cc1f3419ec115ad589504de7f378d99

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.0-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 79d5fd5d1faf902445a7d84ad50b7b09223a1bcc4bdfba3358d54557d9d0306d
MD5 1d8513bf3098ed1370640bcacac0a78b
BLAKE2b-256 690596d870cb356d7f3617787f9fc5e7a40ea866811fbe520e4d6064769b026c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.7.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 3.4 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.7.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 51476b1a878814ebe4274022fba9be3594d4970e057b41f071828a1a90ff165c
MD5 870da1d817531a15b7f1bd1f1a05babe
BLAKE2b-256 3a9a42ae36d28eccb32f5efb2674647dcae7a491e55d54f103eb3f48e3f559e4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.0-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 beb9bd8cf8c3234e9d92790bff3057a26c36e17fd9fa804428bc22b71a05de08
MD5 8c68ff3fa23067ad04257a697e62e84e
BLAKE2b-256 24bd2534dfd6929187a32a92ec59e39154e5b00a29f3c4dbcb3d62a10e7cba1e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8c75ecf28b5277b59bce063e1436527e128705d822a93bb12600624cc6baef29
MD5 662de424568833ddf28dffe9d9690313
BLAKE2b-256 a103f003f0c8393a57975f39aec2aaf7358a6bda4d371c1e3347da7274ca821d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.0-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 1b263b2926f60c376f04c2eb7b99c479fadd46b0f1f6f248790bc2f6046b44a7
MD5 4ddf539df8677a874c9ebd9a976d1f60
BLAKE2b-256 7ee40c0463bb3b27cbbe49e3803bdc586616284fc124418da1fb7c825f52162c

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