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

Uploaded CPython 3.13Windows x86-64

kglite-0.7.9-cp313-cp313-manylinux_2_35_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.35+ x86-64

kglite-0.7.9-cp313-cp313-macosx_11_0_arm64.whl (3.2 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

kglite-0.7.9-cp313-cp313-macosx_10_12_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

kglite-0.7.9-cp312-cp312-win_amd64.whl (3.6 MB view details)

Uploaded CPython 3.12Windows x86-64

kglite-0.7.9-cp312-cp312-manylinux_2_35_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.35+ x86-64

kglite-0.7.9-cp312-cp312-macosx_11_0_arm64.whl (3.2 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

kglite-0.7.9-cp312-cp312-macosx_10_12_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

kglite-0.7.9-cp311-cp311-win_amd64.whl (3.6 MB view details)

Uploaded CPython 3.11Windows x86-64

kglite-0.7.9-cp311-cp311-manylinux_2_35_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.35+ x86-64

kglite-0.7.9-cp311-cp311-macosx_11_0_arm64.whl (3.2 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

kglite-0.7.9-cp311-cp311-macosx_10_12_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

kglite-0.7.9-cp310-cp310-win_amd64.whl (3.6 MB view details)

Uploaded CPython 3.10Windows x86-64

kglite-0.7.9-cp310-cp310-manylinux_2_35_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.35+ x86-64

kglite-0.7.9-cp310-cp310-macosx_11_0_arm64.whl (3.2 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

kglite-0.7.9-cp310-cp310-macosx_10_12_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.10macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: kglite-0.7.9-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 3.6 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.9-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 45e2db59c9906668369512c2027bd97bfb2e00bc77898549e3e3015df1227c43
MD5 94a5c4ba4fff49d2d07641685731a652
BLAKE2b-256 4de9c626966482511d4cabe1ce1e238ef5e24a1f39ee287281dfd46ee60feaa7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.9-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 2d9976f959cfab90ef04006e0b8dd92522bd73e8b44b414e6e304d19b63c507b
MD5 3b59b736a6f05a334ae7b32e148d1c40
BLAKE2b-256 84743b2323196b9d38be24d0ed741eddd3cb8e700afd0af26c0737f17403ee3d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.9-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ae6130e23f0fbde7c04230341a42738ccf21938622be4a9581b547c6f5d505c6
MD5 5cf7f19e6a2556ad00c84f018434fe86
BLAKE2b-256 1cd6375d8eb1f1c9c4ccbf5d94a32dd62aa432902d3b0a49ebb065ecd3de83eb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.9-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 73c3636563b4bcd940822142c5a21f187e1802d6347471dd04f5dc86a51ee3dd
MD5 6dd60e0b5cffa66b60d3a6d736312872
BLAKE2b-256 7d4b5a2183c8e1a7869d5730ea02c1abfbade20b5701edebfe41e369b443169e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.7.9-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 3.6 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.9-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 0d01976c188f33087b0766c12658218f3dd252f766fa1133b690d45754d9cce6
MD5 0f63e3e05c774bc5c7c508c075773152
BLAKE2b-256 e9df8689ddd4e6257ec629090afade5c40a53b0acfa7d079eeb5271a3497aec4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.9-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 a43b9db2f61c9459119925d173d9120ea174e16f121b91ef29bb5a41e0f2c5a8
MD5 57ace3bb32e637a6bad0a815e0299779
BLAKE2b-256 3af7cc0cb44dd156aebfe4df98063a6f9d33851a599f8d26307e485cc4f2a929

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.9-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9d8344555e8525a853f46439eb173218041b1c4abcdd797442edbf6b139e80ee
MD5 2a3bf69646100c3481e6289ce3310c45
BLAKE2b-256 b0bb9e8f3a924d90a46409dd87ce18f6ec0fc18b30b7b7764d8d09e29fb4d7dc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.9-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 0ca76f60397f9797edf8a851a7600015cb72dfcd216d2eb7eb0896baf26a76d7
MD5 b2d35c62ac2f87afc758c3888fd538f4
BLAKE2b-256 2941c44331235d8240b29f488fad9a7cc0f58e5b24ff91c4ae3372be50adb539

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.7.9-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 3.6 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.9-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 64f98859a68021d01a305e963933590fe08388163d0d004ecaaac9563e70f95c
MD5 889dee7076b05da3826cd19e75206e46
BLAKE2b-256 1aac4cb98ac37c12f8f10e4135c6ca1e49dedbe15a255a05f468c808f7a409f7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.9-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 d7d66f28528e21a690d97943315336a96629dc74905914251c20877b1e694dc8
MD5 21ae0c1309f8962e4b0433e982d40f1a
BLAKE2b-256 43471fe383e7db5c21750d13844150aef452be736600a65774d7951c96244ee0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.9-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9f6cc64b03bba859b3dacce3c671debd310a02a8ccdf496eeeed64b5a0756cc7
MD5 3dd7c94092d089752d9bc4a7556b63bf
BLAKE2b-256 0f6e18f7cd7bb18df13122d0a10adbf0f268e7d488826ea1cf2f084a37f537ad

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.9-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 48c8105118dfa58a1ab9c42b2ea797ac3d3fa92fd8acd0d12365c009e51d3b61
MD5 15417c628dd92016d178f0270ef09e6a
BLAKE2b-256 79c5ceb18fb543ea0f3401b6bde99cbb17f62b3ded481263ba66f7cfbcec05c9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.7.9-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 3.6 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.9-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 762d94a53abf20bbbe8d0167964d1a60fa2a3c92fd8084c5a5d00f284f2bfad0
MD5 3ef55591ad42f0d0ee383b9f636aea43
BLAKE2b-256 2b849b6b1e664027a098a467ab330c24ced9dc796a09a72ea17009e3ebc1a602

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.9-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 ee90b7b83da3166f1e2bc680981955c0c723e00a6d64076374cae349c4e34021
MD5 604a09311263ee0262dc11fa78ac2f77
BLAKE2b-256 52ddd4d8e66b6d0ff4197f3146ed124148a9c39ad8acff31d050445aef0237d1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.9-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 37d83bf8249e3761f9a429060e26d6eac56f1077fc8ccc062eb259f0166f3fb3
MD5 2cb85e166d3795cfc63d181ee321f28d
BLAKE2b-256 1f41fff1c182af7f43a5ad0011db2106b4b697464951ae1caa7cbd631fd59fc6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.9-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 631b25edaf7d02dce788783194ece65b953e5055041409e5969aef6c6d4c848a
MD5 2f095b4bb81e1f4324b66ee80f787f9a
BLAKE2b-256 6fc8e1ac4c5462423d1c178efeb70bf942c8b3229449898ab6bf518efd9c88f9

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