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.2

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

Uploaded CPython 3.13Windows x86-64

kglite-0.7.2-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.2-cp313-cp313-macosx_11_0_arm64.whl (3.0 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 10.12+ x86-64

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

Uploaded CPython 3.12Windows x86-64

kglite-0.7.2-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.2-cp312-cp312-macosx_11_0_arm64.whl (3.0 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.12macOS 10.12+ x86-64

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

Uploaded CPython 3.11Windows x86-64

kglite-0.7.2-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.2-cp311-cp311-macosx_11_0_arm64.whl (3.0 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 10.12+ x86-64

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

Uploaded CPython 3.10Windows x86-64

kglite-0.7.2-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.2-cp310-cp310-macosx_11_0_arm64.whl (3.0 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

kglite-0.7.2-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.2-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: kglite-0.7.2-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.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 f18397796aaa362c3043d697e3edd74d902eb5cdfb7f0f2681e70152034da951
MD5 9959d9aff7c84a9c764fbd91ac6733b5
BLAKE2b-256 9a1d5377b0525cae21a1b264163e9a10a5727bf22df7545bb44fef809c90646a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.2-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 7f6ff37552a20ee8a28c5c35021e10d64c6fabcad101fa27eaaba2c849bd0834
MD5 6661e80e0fa2f3fa2f4d4c73a811a283
BLAKE2b-256 2944bdd5d838eee233ca0115948773a48b1b4676139d642267f5094adbc5bc19

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bb247c605d8692a27bddc59380efb305fdb54043c2173c3133daa9d85f25fda8
MD5 77569e5fc6b366df9c6fcad6304e53c6
BLAKE2b-256 ce5b5fc01a0cadf6451d155d4c5781a7f58c4f4632ac1c61509f90f6f1ca8aad

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.2-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 5dffd48774c5d7cc6c6f6b92ff9c22fd180a3bfa97bbc053c782986ad6103aab
MD5 3908b96824dea81b6413feb0001d0993
BLAKE2b-256 d162ab977e544a34a3f3c17573f552d158995cfece35834b594346f2118384a7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.7.2-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.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 a002193d7e26babe12630817bcf130ccfb7601261e06d4a234f8a08d5af22d74
MD5 98b0dc1e2d477e6d9b97ea47a98482d1
BLAKE2b-256 a02e718edcd7abb4c74ec68bdb1bc594c1498235571b46adbfdc2ca6c1931c89

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.2-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 6b20ee308143ee9f05a1f5780bd688673362c432ead5d02dd828af825115a6bf
MD5 a4d23e83e376fd4e11bdc53cc82a6402
BLAKE2b-256 c9bd558e222def9ac6407afcc40990ecb48029b1d727815c77018eb5e6c4ce65

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 92a217c9b923505b4ba54a6f3ecdcbd956cae8b19b1a6e2e2561afd371e09b61
MD5 01cbffbddf74a6b8a54cebd6630e9da2
BLAKE2b-256 6c3361d2d0cb3026e93baf0fddbc80b570e3d787d07426ec05a17d80cc082a94

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.2-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 5b86b48d5c59464c2097924be0d975d53df3d7ccbebfc2759065c6485bbc0bf0
MD5 508809c52d7756c2fede6fd4429f5648
BLAKE2b-256 4c181a83790c3396491b5277a699e52322df394a65b7b8325e1d8b8628de5910

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.7.2-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.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 714d2bc469607fab5a8962a7f32bd93d13a44974d2e7bf2cfef8221da77c4780
MD5 08ba5ae5c3ab1b503e487c2fb321a374
BLAKE2b-256 7288a6682c52909d8d53272c32abfd3e306ef6c93eb0a0bc5fd8d1ffbdc399d9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.2-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 9e3ebb6f173e39b8ef12387b907b7198aff510ce69b9a8fdd0ac839fe4647341
MD5 8ebf06efb001f29f339f64baa22e4643
BLAKE2b-256 db9f3457ed3fc531a8eead7f5467faac2c2c086e16e7e489e4d444cdb08ade8f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 27e10ca886a8b192ff63b6fe5db8e4dd976b4985837961225a3ca7c702f90e42
MD5 e7819e351ba3a77e08b5ee8ae68ccd83
BLAKE2b-256 8e52398d09e3d7a160595966082ed1a72a8977ebf6cc4a8c54e1be94b61a99c8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.2-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 667cff531856c8ef1897bc286c0f08090fd0344cb7576a58b24420f8cf393544
MD5 9ff808e690cbbfb5470d6296d5e3b92a
BLAKE2b-256 1cf8f675b18f551f6d0a8b6239a3c6f0d841c746c5d79723ae8f33245036ef9f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.7.2-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.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 61f38b9a29833a2fd097e1851ac858ff0c04b1eb3869f34bf375bcebc0eec08c
MD5 18c7314a6a814cdf0f8c3bd9ddc1fc44
BLAKE2b-256 e92a664ca2d69aeb872390e0040a2ce99a767145702716fce3703f22e744c9bd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.2-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 8a7954bfb0a448c9b5d1b157efdfefe1ace481ce86b6e9347818c6b70b9d7bd9
MD5 7e05eaeadf390a6574444af691c13ffe
BLAKE2b-256 b46dd1dd6b354b66ec5b5b9f0b054a57a2931e108e2047dba7ef93677cf72e63

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1ab650f868b6eccd4b9ad3f95d37efe50a77ce4a3f6128cf67cf7165e4cb2889
MD5 a6dff1d817bde5baa2434c47c7bba868
BLAKE2b-256 18b8218d8e815d8e54c17dac810f9d5c0db3025e6359b491426666cdb57e48b4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.2-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b61ca8e0cf8b834de2904b02c1326cb05e45476e4b3bcb473579c74cc52b5f3a
MD5 f53e56817f2e1d7deaa440f3578a504a
BLAKE2b-256 c8502d7ab378bf07f5acab5e0a0ad79a8574d21619143acacf50a9382c80f69c

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