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

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

Uploaded CPython 3.13Windows x86-64

kglite-0.7.4-cp313-cp313-manylinux_2_35_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.35+ x86-64

kglite-0.7.4-cp313-cp313-macosx_11_0_arm64.whl (3.1 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

kglite-0.7.4-cp313-cp313-macosx_10_12_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

kglite-0.7.4-cp312-cp312-win_amd64.whl (3.5 MB view details)

Uploaded CPython 3.12Windows x86-64

kglite-0.7.4-cp312-cp312-manylinux_2_35_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.35+ x86-64

kglite-0.7.4-cp312-cp312-macosx_11_0_arm64.whl (3.1 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

kglite-0.7.4-cp312-cp312-macosx_10_12_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

kglite-0.7.4-cp311-cp311-win_amd64.whl (3.5 MB view details)

Uploaded CPython 3.11Windows x86-64

kglite-0.7.4-cp311-cp311-manylinux_2_35_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.35+ x86-64

kglite-0.7.4-cp311-cp311-macosx_11_0_arm64.whl (3.1 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

kglite-0.7.4-cp311-cp311-macosx_10_12_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

kglite-0.7.4-cp310-cp310-win_amd64.whl (3.5 MB view details)

Uploaded CPython 3.10Windows x86-64

kglite-0.7.4-cp310-cp310-manylinux_2_35_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.35+ x86-64

kglite-0.7.4-cp310-cp310-macosx_11_0_arm64.whl (3.1 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

kglite-0.7.4-cp310-cp310-macosx_10_12_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.10macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: kglite-0.7.4-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 3.5 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.4-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 aa303b7dfef41b2ee7e5c415076b4684610b28d35176e26a41e31505f2812f5a
MD5 d99a6ac1e9005741dee06d74bb0c5f98
BLAKE2b-256 4a1fabe8ce744ce0717b0eb1933831b3f53eeffb166a482e6a100a355b932dcb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.4-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 63a2f2a9025b2de6f2e4a7360bb60c653f371f13ae4c68bf5a10549e30213346
MD5 bc85a0e833e96eea2014075b666a7506
BLAKE2b-256 ae88d93a4deed656b4f78207c9288dbee6b7a52c08b2d9b21090c8d51ec80409

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.4-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 369a4ebd9454376dfb3ec2a24a5a03b6cfc705c870071820c388140058c5b583
MD5 578a6b645d89c8bb0b68468572dc4ac4
BLAKE2b-256 36fb0f6cc0baf40d73ec31773b4878a17c41d8be14e8d26b487dea90cf35f503

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.4-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 751c5383fea032f76c0445a580e52e00e23e45258e75cf880c206e638e091eba
MD5 cf1d361dfcadb075afeb91a9068119c1
BLAKE2b-256 4e08293a5f8047ec673d4a511105d27572f0bc3b4169e19999094c0c36a7dc2a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.7.4-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 3.5 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.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 1b3528ea8af9c90c36256ccb53f10d62b9322abcb4a89e4be4cc64417c73b86e
MD5 f4b992791b92eeac5bdf101202ae957f
BLAKE2b-256 980394fa166a076632575b7e57b49afc5865d3a1edde9f33d1c9ba70f8e40596

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.4-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 24e509e1604fd63ff1bb0c3b3b68723239b03be333bd4ad191c68fa209fe2040
MD5 0f6931bfb5d2dd84939ed73c3bb64678
BLAKE2b-256 c5292778ec82adf6d7de3482af273869ed9da2ddeb9cc7a57f245959dd4eb7c2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6dd353ea437fe4cf947bca90f0362b3c66dac03a7e2200c06b4376e8f1a12b9e
MD5 f1e1758ae78765ee629ef7e0bb3e472d
BLAKE2b-256 7fc24205e66e0a10fc3fc3342ac15dd13907f47d95083dbb58753d7fcb3edcfa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.4-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 171abcce9952200d2a445e25c809d357245dac7df4f9dbd2ed8130b61f887527
MD5 0e3cd74945b3649553ccc0c8aa8e4cc6
BLAKE2b-256 36ac69cc031526b2fabf846738a1a565a2d1ee36ddd22da8961f079ad7fab458

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.7.4-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 3.5 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.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 8be297e51536ce8d3ef835803547d87b44956859d2567eeba446e4e133191892
MD5 99bd87b38bd60ee4dc762f9dca29f5b7
BLAKE2b-256 4d7b47d1a166a7ce42fb020ec04b2a2cb2d5961ef851ece0c6f3f86f39c491b2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.4-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 b1bf910075078526181c765d2e96ba058636c8ec3c05083a631651b329e50dcf
MD5 a2fd5c6f9be2a883a84a5697cdfb0c9b
BLAKE2b-256 2be7fd08b0efcd1fec9fe1aba747022fca43c2bec73d69eb344caa5a03f39ab3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 43f165a7ce75880b5e9dd318e0cde40bf57130a573ff0d5f6c6ce268b8dc7c1e
MD5 074242d09557a6e73aec18828ff57097
BLAKE2b-256 ee969e77512c0b949ed3c3aef3347c246dfb750b2bd4f4ce20ecaaf96d410f21

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.4-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 124ad3fceb7eee06d1c363f9ec8babf0fb1a5591e7814b79e9f89fbd08a625be
MD5 fc38013be23114bfdb9943ab45763df3
BLAKE2b-256 1685a1b6bbbc50f08ea69155e83cbbe4d0ff1c61d0e8b6d8556f00564e207c42

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.7.4-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 3.5 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.4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 4ec9f3846f024fbfa7d814c852d2074547269eee317379de849e697dbb3f0c1f
MD5 b9fe42f746a0ba72a4110e146c8c5bc6
BLAKE2b-256 19a61a6ae8904f98b197a7735c58a03e6d5b1c2d024e883ce47f326c348d713f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.4-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 fc096149098f8bce8bc517bf1379988f779415f6bd7628eb49829b826044c331
MD5 5ea17248506195678555f085416c84df
BLAKE2b-256 876defee8536ecf2dc60e76beb4645ae5162af0009e3a6e2832063dd7cadecb0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.4-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c24a61af822b03edea7191fd9417b6c6abaae80815384ab751bbe6833ae9c28e
MD5 a605f98d8186297110f4e952fe12081b
BLAKE2b-256 325f5d29ccb2a3f6857e4162be329d890961354aaa239c4b04268ecfc8f5ed4d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.4-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 69e45c3ee0cf435c685e01522b0e7554be9e67bb576440e4805f664e4ffd0291
MD5 bf144434eebb13a08ffee30a72726b15
BLAKE2b-256 bffaefe017661af3904ed59f2a998bb8e42689de895866239ebdbf7a562a397f

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