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

Uploaded CPython 3.13Windows x86-64

kglite-0.7.10-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.10-cp313-cp313-macosx_11_0_arm64.whl (3.2 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 10.12+ x86-64

kglite-0.7.10-cp312-cp312-win_amd64.whl (3.7 MB view details)

Uploaded CPython 3.12Windows x86-64

kglite-0.7.10-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.10-cp312-cp312-macosx_11_0_arm64.whl (3.2 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.12macOS 10.12+ x86-64

kglite-0.7.10-cp311-cp311-win_amd64.whl (3.7 MB view details)

Uploaded CPython 3.11Windows x86-64

kglite-0.7.10-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.10-cp311-cp311-macosx_11_0_arm64.whl (3.2 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 10.12+ x86-64

kglite-0.7.10-cp310-cp310-win_amd64.whl (3.7 MB view details)

Uploaded CPython 3.10Windows x86-64

kglite-0.7.10-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.10-cp310-cp310-macosx_11_0_arm64.whl (3.2 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

kglite-0.7.10-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.10-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: kglite-0.7.10-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 3.7 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.10-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 8eb402e734ec6573fdf4a5cdfe28d31e1d610cdc0740b27dac613c0dfaec94b1
MD5 26f1f3449fb52d77cbeacb295e4daf25
BLAKE2b-256 c5901d318d0d197bf0b511b79fab39d69d6e24b7549d3d1c672a00375c78aed1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.10-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 c459e9b217ee084c519f1a5daefb7448e5b11d8178960f8c14208418f0cd7fc9
MD5 b12d91b73d9e9f3a9f06976d04b3e163
BLAKE2b-256 a03ef99457722fc55ad101eddeb265d996ff4768fb96193006acb6cdd2ff010e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.10-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e4d49498f6b86a3641aaded36dc61f9327b4458b3c0329d33fb4c8a0181ab9c7
MD5 4ae0a583c34f9731571e83d10e1d1180
BLAKE2b-256 6384d1feb21f3cf0756cee3a8239c219cc046c8829ae30245b1801140344bc67

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.10-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 0bd97a892d6e21bb2b4264908a3106e53b7bd7932485a06f582e696f2fd6c5bd
MD5 b33155b30b7bad689fcd2d8c332622ae
BLAKE2b-256 405e306c726848e0c463bd533d26cd532cfd53ec9d978174ae0bf58114ea4739

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.7.10-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 3.7 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.10-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 775be46c7f8069eb8dcce3dce24e102f3abf5fd0203d28598e7910883ab1bcaa
MD5 a17e798209ea7a46d2ba2ee59509e61b
BLAKE2b-256 a60eff59a8a626193a1a174542a65d5739c8c09c4f05fb2e5c3a5b455c6fed46

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.10-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 a4b59f689008f47502c7f85de9ed361367a4e427b56d6935fca51cdd4f3d9c4e
MD5 0f52a67e0d6344c053727bfc937120eb
BLAKE2b-256 b9b8c6af96ba6362ca8583927c0c6ed207072a4268aa35503350201011d8b1ab

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.10-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a5cd6f07fe98b51253c801a23721f0daf82af84fe2f95ff19a2b2e533bb19e14
MD5 4faf73766262d569d588014c7d5bf1f6
BLAKE2b-256 b6e312c5393668a930a71520ac103d635236555d468bc75eb6413df8ba8e45e1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.10-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 f76c2c1ba9ebd4fabc8165e1864a5ae2d947a1f15d975360338f8055240f70fe
MD5 40850b058eb72b6f7425b5f5d4e0f3dc
BLAKE2b-256 179a8685377254b2734b05b9f792de19ed8c6747b16b6fb24ff8fdbe7a11b65c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.7.10-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 3.7 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.10-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 96edc652ee6b314a25af9e85ca77432534001bae4a3185917fb903f1a31b8891
MD5 5e2992ac3d7232a17d22566b8a073c46
BLAKE2b-256 83a6fbb5ff6d444560acfd9abbc5ad686705133bf8361099f6e4cbf8c6e44150

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.10-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 1c95df39ebc18ae0e466a79778c71bf02299679fa15d80220f433d417d6eadcb
MD5 bfd56bfad3726370cf076c0a16625a5c
BLAKE2b-256 b9eab819001a1d5043820c7134767e05da56b2081a0754ef2ca3abe7ecc65741

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.10-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e9eeea30209ae3ac5eb21a4296bbebf0e912aa1891b16e247982b1fd34cd0d42
MD5 4cb9968ccf4b28e476acf6015611fc4d
BLAKE2b-256 4c5e5d0de9955ee85d94e702499ed4b55450091f877e167d3f43e21a9ea50a8a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.10-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 7f70f593b78cc5feff0f8467661ca2cf4fc8b42c72c5ea60676b1a79cb8f8626
MD5 e791e3f61f1c1697abf5d2fc71b7f042
BLAKE2b-256 c26bda1afceac5745f5d08563396ed74fae85bebaefa3adf09f23129f38a0514

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.7.10-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 3.7 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.10-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 fc99ecfdf268814589e2c052b2d5dda88db0ddba87784816358634036396a7cb
MD5 30d7d39c49e212e90aa25379fa865ad4
BLAKE2b-256 ee249f0fca4ef1b03960acc57e81963561946e57c6d3eaa4c5faf45eb54e85b4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.10-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 468b4de7ceb90fdb6d0cf0b989cae1d496a00cd430ae518b76f6d78ae7b1345b
MD5 153176024c2c6550f75af9698b8d9e4f
BLAKE2b-256 04c1e6e96bd2521aba305203e0966854a417ddb01ad3b8a73bd88d05b81aab6e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.10-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1394c0d05f27db0d6a98dd22a27a414bea10c15ec05b731c3035ce6bd2dcddd8
MD5 80fffbb8ea95a20ace73e3fa452a984f
BLAKE2b-256 cb408036d219912c5eaafcf01e60c9b28664b1b3837a9ae7c769054ae0ffef11

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.10-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 6fd6b500f1cfe3a3ba516a6325f4fc28bdd69520165b0ca65cf29e79d45897b9
MD5 7e2812e141efd6ed313e818f9424379b
BLAKE2b-256 f0f8228be98025d082c891d23bda63cf811b28d5c33b154ea2d0af90f03eec1b

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