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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 10.12+ x86-64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.12macOS 10.12+ x86-64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 10.12+ x86-64

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

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

kglite-0.6.11-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.11-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: kglite-0.6.11-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.11-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 49aaf7f6a9e0d1b5ce1845ecaf094643853b76d2653da22e79ee5a5c79dc1f1c
MD5 97106c28aae393bd9c28eab6084c5e9b
BLAKE2b-256 bb24db04d2ed450ed456a8e25bdce9a301d570947155b290bbd65b9da05a0d1b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.11-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 e0b641b55f73ceb0ba8a8200cba73bd185012db8eb03ddf66840156fc313bc90
MD5 226e13ceedf7631b398d8106f04278f1
BLAKE2b-256 6dfe06953d7b864d3bc9a461d92c618089e294652d4999e7b74ab0f0a8691604

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.11-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ebc124e1752edb728370b78109b5b6f0069d028577638b66c0ec8fd3903604db
MD5 72b2a12dcf4a18c97c84d3f7ea55afd9
BLAKE2b-256 072b3fdc535752beb7215d0a8c47b3472cabb601844a0890a786579f6d325200

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.11-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 3d75b432b4573284d0535fe3fd2595bbbe213cd3a8f394c3e9954506971de0b7
MD5 3c6777d363a9c5adfcfefe53063967f9
BLAKE2b-256 adf9f79565a45bf1935ce673277a7c4c14ab33277b609de695008edc0d53fa1a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.6.11-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.11-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 ece70f89bd4f7645cefde9160b4d8a80a0152fb808d645b747233b18072e7d83
MD5 875c5c73d42375b297d8c945ce1f25b6
BLAKE2b-256 85aba7815fd3f167604fa24b7631b4182d7fb9d41fffc18d640abe3692d2e22f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.11-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 2d21d1544ffbd08920012fe35eba4494a78ae327865e3bc973e3700987b6196f
MD5 40e61c1bd18a4cda1454910f38cef4b0
BLAKE2b-256 d902a2425c0493f7b68a680f1dfdfa83a0f1692b357f7983722159ac03fed64a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.11-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3b2c383370303e7ce5bd7bbf1c72717a8ceb09b4273087dc6aaef5cf3d3a560e
MD5 280d12b1a86c7b9fe2c5660dcf57df66
BLAKE2b-256 b232403c0146e1ce0b758caa01ac9cd9f87f4617c9be97e22bd38d1e96b749a5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.11-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 18350c4d99112dbf4ca8160e1441102fa1f3b9d6c9292bb40100bf22535c2423
MD5 1ceadde0a0b848bd0f9e0760d5996a2d
BLAKE2b-256 2092b261e6db7afbb4b4cf84085653d9d5d91f571c031c5133f6bd1d8a5edbe2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.6.11-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.11-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 12d05c81be9f20a1b0797589b4f2e58ec92ff1d7c5174f9c25760428fd10d3a1
MD5 ea7cabfedc99cf5085c46cfbc7a23022
BLAKE2b-256 c80b0917e5a68b110bc9545868adcdeaf6918df1a691bfe048698dd801f69bd2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.11-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 3cc04541d0d11cc9dbb0e6506cd02e4e2e1ad74e1fd9bb153a7656527ad41c5a
MD5 bb8ab2d11f019d5c8b60552d9d8224a3
BLAKE2b-256 8b7ccae41f346dfd652278a7f06e85b51a246537e07a350446eecc49182c06e2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.11-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3d6792c889e03b6e838ea58a58126e4f89a3a7593bd3a825de46ec8175736f58
MD5 c78d2e863c179a2a4b89c6d3403e286f
BLAKE2b-256 87442ea649a42b6ca4c61f174e63b24a3b36fa7f5780c813f1ebdbcd1a3c00f8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.11-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 8cd649631f57e26cef0ee07829f0f0711087144b1be739a8c7a75d6ef4fa808f
MD5 76d563b89e0400c8082aad8f540b3f02
BLAKE2b-256 4c8dbaab1ed29840dbff71aa60db28d8090345e49f99b5e6979450d1f3c3f0ba

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.6.11-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.11-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 e70739ccc5d15b140cde674180d60a2f70bbe8e29c815d12f31d589967a59dfc
MD5 c0e72f1d2a2c99c1c3a2dd0897a52cb5
BLAKE2b-256 b075f0b40fa164c165e0ac3ce1398c9b2b21011f800eb94ae65bd211695148b5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.11-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 d0510b2056edeac5b706c6e5657a7c9011077e428ddf920d9ed5357671be275b
MD5 5bcaf9d84d7fde8c78f2798a380d1f33
BLAKE2b-256 40a3beb36dd4679fad2602034781730ab3873882c2c901cbcbca0c6a894aa895

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.11-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c037f8e5e2068a4f9f4d29b6d276198d4ff8e997ef7ba28706a4e522cbe09bb3
MD5 f79bda121d4ed9e71716f1da253d6e6d
BLAKE2b-256 5b0274580fb018550f7c51ccfbc51b1cfac52f73f17a4fa7eae307a5a6280b04

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.11-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ceaf9be8a067f1925f87217946e053d8453d4986b196a95aceb87dd07c6040c0
MD5 5b74b923911717a2c9de853b3f6150b0
BLAKE2b-256 9fd76279b793496a4e027cf9d87b3a73b8e0f0de2e58352854a53753a1486db1

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