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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 10.12+ x86-64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.12macOS 10.12+ x86-64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 10.12+ x86-64

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

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

kglite-0.6.8-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.8-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: kglite-0.6.8-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.8-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 d851ce17640cd32b9c1d12df64601bbe81ac0b54d20176bcb13dadfeb82a5cab
MD5 f92b618ca77123ceb14a79718599e0e4
BLAKE2b-256 bcd439e16c5d6b617bbea48e19a271e33c5033f0a745be94e45d5da1beb80a06

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.8-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 538e85c7b135780dbe3b1f2a5b5698e3eccf85d2a9c09c53958df04cf156a541
MD5 5ccfb2f9a81251946748cd31adf9228d
BLAKE2b-256 91a938d24dc179fe581ce6756ce9d2cf73829d65e4538d58a9553bdab52a4cf6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.8-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 968dc639288780151cc23f3fbed16014f92233320132cb7f793ed1b2d60b3845
MD5 f89313a93d886f2dadc9c6564510fbeb
BLAKE2b-256 9ff169bca692a4e5bff044908e64b515b03cd733141e24a15f93789a9ff2ff8f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.8-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 047adc02d45f41f90b9f806b6f081dd685aabf09b931a3302acff1e4252aee53
MD5 e6773125cba9cc3bb480169ceda01e90
BLAKE2b-256 ec3388f136f58db42b75082f639d9eb809ad6a01887ffe1a7981770282dc04f8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.6.8-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.8-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 2716e696b0125bcdcce0b839f00174b5055574fd3d08f0f5b207e2f71ab314b1
MD5 a9cf4221043e3d764ca05dc4f73464d2
BLAKE2b-256 bbb85de40d84c4dbb3c500d9b0260426a6d74b2aa54b11e5adbb3b15a75cae28

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.8-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 d801c20c20b9c8da842b72fe7dedd27226a5f1a03c8e84606e4515388b0c9f51
MD5 049ace9e8729778bb896a212ce6ea33f
BLAKE2b-256 6f4c905884039cc6d11ce8a6562a5950549478c03576119766186f9cffc2defc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.8-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d28c8a8ec7afbf0d5f025284ee07495f177e55e7eece33f1ee4aaa8da31672fc
MD5 ea077c92ab6250333c7e0b0dca7887c6
BLAKE2b-256 50af6804ae9ff14e7756fc5bca219fc0551f690ab70c69cedc0670e31d153b3a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.8-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 e1548129f8e1e8639d78816a98c44eb4f9fa883474e39d4a71ada49895785e9f
MD5 5cfcac961593ad4ff0f759d44149f6ac
BLAKE2b-256 d2a1d85f07e1fde9567a661712ba0fcabd8ba1465194090c9232de476a9e2f54

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.6.8-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.8-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 fc3b4bf69cb500d5555d3ca7ce2b750640303faeefd72bab0334799971702ee5
MD5 af1439d03a060a72f4340be3f517d084
BLAKE2b-256 62a344a40602ca1e334096294ce5b0f9c9701936c86e7ce0c3840b26efccbb7e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.8-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 ad94a1b16e5ef027d0ce54c31e50ed939ed2041b035cfb8490c4dd076e272cd3
MD5 0fdba2e0d47ce00412766df02c886698
BLAKE2b-256 832bd07d9d8cb4b8a7966b8e3024727f8176df73ce088534b96107db8be10793

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.8-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fe072c3fabed194f1b583d41b89326d838fe0aa83e78134c7276a82246d3b665
MD5 7a75f02f4b6d9ffe05d973ee15a744d5
BLAKE2b-256 03febd7a4e563ebe8368652fe66a1a71310585f4f86443c3f5b0e0c156576140

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.8-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 0a3e86b94308d9e0e71388b41747ec77d451d7d249951cbc3e1b0235ed72f565
MD5 7d54959280b4f42e8448a14e2d76702c
BLAKE2b-256 6e55c51d65196a33af810cecad8a6685886e776c8d6f88a573155a395db8a382

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.6.8-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.8-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 b7f2b46ffeaed453cbaccd76362e041b29fce904da40f18324c6c1445069b67e
MD5 f36ab52c947752e09dc9506ddbfca7ed
BLAKE2b-256 4a851cbd66eab999bb59d4431914438d4d79c567049787f2cda1f57021a8044e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.8-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 a1d02a5f513840882357c5bfc916146833a3fb41053c9b4b036dde329f243469
MD5 a852fa2076c914b3b4d8d20d3a3ecc88
BLAKE2b-256 a4fd03f00c57c5f109e7da94e4cf97138696c9f936722d3a6278ba93d2fa64d5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.8-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f36fa2aed2db68dcee1e330d3640426e0fd556d4220ddb2ac5eb3d7eacfab7d6
MD5 25898c8117796cd9f4af3472b50053d5
BLAKE2b-256 c0826ab69f651985eafe3efa92b538946676edd2503d75934df43c4f6c5dc4c1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.8-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 95d2f619bd425c253e1571b72d79455346caa2c2698f3e9095cb0d443086195a
MD5 86776fe5012e8fab6b16d2998c035a3d
BLAKE2b-256 793f655304fe0acd3838321b6c2360b9de0eed40abf143ffd575be0790349d1d

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