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

Uploaded CPython 3.13Windows x86-64

kglite-0.6.4-cp313-cp313-manylinux_2_35_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.35+ x86-64

kglite-0.6.4-cp313-cp313-macosx_11_0_arm64.whl (2.9 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

kglite-0.6.4-cp313-cp313-macosx_10_12_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

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

Uploaded CPython 3.12Windows x86-64

kglite-0.6.4-cp312-cp312-manylinux_2_35_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.35+ x86-64

kglite-0.6.4-cp312-cp312-macosx_11_0_arm64.whl (2.9 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

kglite-0.6.4-cp312-cp312-macosx_10_12_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

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

Uploaded CPython 3.11Windows x86-64

kglite-0.6.4-cp311-cp311-manylinux_2_35_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.35+ x86-64

kglite-0.6.4-cp311-cp311-macosx_11_0_arm64.whl (2.9 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

kglite-0.6.4-cp311-cp311-macosx_10_12_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

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

Uploaded CPython 3.10Windows x86-64

kglite-0.6.4-cp310-cp310-manylinux_2_35_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.35+ x86-64

kglite-0.6.4-cp310-cp310-macosx_11_0_arm64.whl (2.9 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

kglite-0.6.4-cp310-cp310-macosx_10_12_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.10macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: kglite-0.6.4-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.4-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 588d76f403b0205f0060d0d23b182d310e90d3a76e71ec45d0036200fab89017
MD5 ea0d079ea9ef48c1a0d7453eb4f8498a
BLAKE2b-256 1017d63ee966e33694824686b55bf5acf032eeba8d890345e049b00256e8a12b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.4-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 eef5b568ad92c29d6c6cb03f3b3d47728ef20067597e86eecac1a1024f91a9b1
MD5 f4db9177b6ca4df0f9d3f965e6825cf1
BLAKE2b-256 bc534f339572d02b7093695b9ba77de75dc8b9458ed182c2ae3f343a8deae6ef

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.4-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 24ab64ce6df2413c95f0b3889637890d87f64aff087125098b22eb4cde9068fd
MD5 1b643f11297e735b381bd0e48e1c8fcb
BLAKE2b-256 b24d142542b199cca8e02cc26cd012907f9b61f9e9a7ea741219e1adbfedd1bb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.4-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 23f04a24aed0e68790516bd9d3f7248a5f1bb3d96e9055ae3e980aff8eedef02
MD5 c1054652452c6465d19b8099d528d4f8
BLAKE2b-256 91c83a88495598c82c924b65fa884f451cc11b602c7c8fc10053761732c7e569

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.6.4-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.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 3ed247791db1a4405869ff476c2f5395bc0443800302df14135af18f8bcc5df7
MD5 d0c6c318a795ad7a0d522c4fb310aa18
BLAKE2b-256 3fece8e4801c3d2c7841e937fcde54880e945f942aba29bba6feb077ec4b44f0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.4-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 e50091dd16336e30b313ee02d6de6943ee05148f69697da3b1f7f5a3a2616b84
MD5 625aad36ac1334a1767c6fc17c1214fa
BLAKE2b-256 b20988b887abf765bac21609eb89c500ec11d780ade2b30526fc2d768b7ab096

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ef71fd536a419622f563b0e918ba8f0c8903dadf336fcab524161beb6757294f
MD5 a56e8fe7831da8fe07fad3f27bec9ce0
BLAKE2b-256 98bc39dde1b6f82b67a211af817d8663a52fc1b76cadf78d93d5820534f6955f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.4-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 410d723e25fe9332b558bcd6d987a3db590af31c62bb8e8a29aee73a04b2bc2a
MD5 2d63eb7c039aea0bac9f8cb9160b1397
BLAKE2b-256 ddf960f0b2b3ce09b64ffdc2f478f7b443e52b16e8e395102028757f61552049

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.6.4-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.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 499fcf966873d766386f524df3126d780b7f3129686fc33c9866c08c2cb92454
MD5 cc8632888f18e0287c8aa5a6eee7bdce
BLAKE2b-256 9ae01b52a07acc87f4ee22154390b15adeb884f837a28b00854abaf64094ac2f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.4-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 02f347eaa74e5de75f839ae17f0fde5b96b3b8b2c3d8f4d9e6d6c2cc10e1656f
MD5 c38aaddec3dfa760063ddc15c2bfbe57
BLAKE2b-256 27e77ecaa275eb991efd0c4b305aa533db66ecf671676bff40d59575928135ef

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 48279a5fe192b47aa6427cf48d35343527dd149b3c1af5980e981eee71b29ef5
MD5 b5ec9dc9865a1fc4a264e6fef4868700
BLAKE2b-256 15e197b4c653bf89337a0f9fc9066305f72f0ef57f4f0c55fa02ff8384dedec1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.4-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ce383754e95eb58e64b05feb5d0b50e52a96e1049730fe72956a95c7252c896e
MD5 2361be19d3e806ab8594e33e3047ac00
BLAKE2b-256 b3fd40f7bf0bf962553628c8170677908c49a6169338ebde646a557e6a7c5967

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.6.4-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.4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 743a70b13ffc2a4d868db97e57192fd9fcf958dd429b70428680e52e5df91822
MD5 edd76c3cb783f1a2233402e25e0e5d78
BLAKE2b-256 e920e78b24cd1ce470581dbc1476e24a9ac6cd91d0b79d56b5f65b27bf6e181f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.4-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 b79da1b3b3a814f3be10e62ab17567394da6ccc561b8f3c512505090c55c831a
MD5 5af1f67daac0b2e6bd13acd69c4e3349
BLAKE2b-256 f23ad5caf5d0ec6cb3f541d257775eabd6919d40af4f591c8575a876434eef01

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.4-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c80a0ea73ee6470aec13e5c5a956eecef8c85b078a0bc7302d39329207dc93a4
MD5 76629a6c6c6de1e29b68a69758f83213
BLAKE2b-256 ceefecc2450fdcc3549476b2327981171d2f7c2634bf48df7c0415797a842eb8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.4-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 93372b6825fcf99c4b7cf069291bc5d19c3f68a458a6e512fdf1f3a54a7b7e85
MD5 7977aab629c2b5881b8074d4b58619dd
BLAKE2b-256 d1d23f7b732af9770d181b5f8573b6872fe5b00d545f8b9e90ca6de670294261

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