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

Uploaded CPython 3.13Windows x86-64

kglite-0.7.12-cp313-cp313-manylinux_2_35_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.35+ x86-64

kglite-0.7.12-cp313-cp313-macosx_11_0_arm64.whl (3.3 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

kglite-0.7.12-cp313-cp313-macosx_10_12_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

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

Uploaded CPython 3.12Windows x86-64

kglite-0.7.12-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.12-cp312-cp312-macosx_11_0_arm64.whl (3.3 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

kglite-0.7.12-cp312-cp312-macosx_10_12_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

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

Uploaded CPython 3.11Windows x86-64

kglite-0.7.12-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.12-cp311-cp311-macosx_11_0_arm64.whl (3.3 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

kglite-0.7.12-cp311-cp311-macosx_10_12_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

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

Uploaded CPython 3.10Windows x86-64

kglite-0.7.12-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.12-cp310-cp310-macosx_11_0_arm64.whl (3.3 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

kglite-0.7.12-cp310-cp310-macosx_10_12_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.10macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: kglite-0.7.12-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.12-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 3cb8ed84f3b91c06247520f3a2e94b158c9b13cf13980188dbbe40edb5b67258
MD5 dba46209dd6db66a791e31fa32c377c9
BLAKE2b-256 3c9824d1ff573c260b6b1c76c241ce63645b2b82db907f08c4ceb1aec002b7f2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.12-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 309da3183a928926987f407a4d6dc501523c346b83c5ca322deedda4e0615080
MD5 ba45fead0be0c204619454c196b1009d
BLAKE2b-256 1bb985d208e3f4562a803989241af83d881fee836d66ff7edf32673f090d1f64

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.12-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2763400099e81a412d069e47ac5ccc684755f68f1586bec1bd2833e03f7c52cb
MD5 e786c46a7320956708e3d3fe3e4aa85f
BLAKE2b-256 53251140d28d4c2a1f66bd4369451f095cbd5ed50d134a2f2aa8125798be5cac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.12-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 a784f7a08fb91e6e14b7f7591e8f3d75c1fb00cbe24026580203e56c7033aed4
MD5 a5a3c539f9a94897cb431187e0780dda
BLAKE2b-256 04cedd616106b08a1851a159340a02b692211ac76b1fd0bb691498d83290f302

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.7.12-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.12-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 38ec6c03dcfad2c9d8cdc696215b2b96da003412d1b181d824ea54ae5d545c6a
MD5 3faa23d225648975dde78279e9e85a04
BLAKE2b-256 029ed8871deb83f3eaf0b1918f14e43bcf507c94d0652427e7c1a9df222c2720

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.12-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 3c6896412e7cb613e82e20ad7b292bcc7afcf9089b1bbd90ee3264efb157e3d2
MD5 0f07feb3dc826347fcde72a196fbee08
BLAKE2b-256 61d76e39a419416ab0fe970108b8bdbba1c923d0db5a9d07d774cd1793d3c3c6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.12-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e665c4624cdd1e813da40390f42d01857ee1a1be6315b6247d65822ba2e2a689
MD5 091abc268b63314e676447227aec2c07
BLAKE2b-256 a675c31af66d9b8adb34e43c0db71f732e42a799325a09993ccb9928247fc6fd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.12-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b3e06c69b380a22fab7f4387826bbf0a095a6e63551e3b29da89c3675f1fe8e6
MD5 23867eaaa4ce1c41c8ef3f28d35875e5
BLAKE2b-256 76fdee3ad5f359bc74ae48eaaed15ddea389d24fecb439123b5fe4196d3ce893

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.7.12-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.12-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 404503924ac7b4581eca84336ae498a335d6d7c0775adef3bbd0f2fe59c0990a
MD5 810b9222b1c00d5d5bda1d951985971a
BLAKE2b-256 267930e823f6b838de852489e1193f2c74b239fd65aa4867deaf15dde450303c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.12-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 a24ffc0e90f75b9c9258876926d8ef6182c97707b6132d35a7121a39e95aec7f
MD5 c7d9ed13f0369cd734fc9c54698052a4
BLAKE2b-256 1c0d9a0a22934de464bfe42c721e7a9bc2a5a1fc372c22119215de924793414d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.12-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a70e003a9a12402dedf5d6f409bd476b32662c335938943ee2eced363ad29903
MD5 1435ff470d187dc2cb87d1284fedd835
BLAKE2b-256 c12e10112282b1fa64f08b81ff3edce1241ab24179ba70ef3e723548ba13e3ac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.12-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 9bc844172a03dbfad8c7d6cb9761dc4f0ead5f2ed806e433697c08cc99a6e0d3
MD5 d629e1a9a207dad6c30b1578cb10189f
BLAKE2b-256 b81d9f5b5edc654b44cc809b666f6c675e290f3dbe54e642ea646904d2a569d9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.7.12-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.12-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 6f895ab65ea1ed5069794c2ffd6210c0659d71e7c0a77a17ff952cca5eea0551
MD5 1cdb2150cede863141a0bf48f18a3269
BLAKE2b-256 be0bd23cda628b61e953016175dbba697f256e51548bf3df0bd3bff319d3a3db

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.12-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 e3758f1caf75771f73f73f54ee678d28114ef89e44c165bd493a8ca959d2c648
MD5 93a122c475feca0bab80bd0d0cd67ab9
BLAKE2b-256 1bf75631ad108b91bf9ebcea84acfd6f89349171844bd097973ada73201f91fc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.12-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 82a35c28970736c888707bdc2df93efeb9036604886e27048a825a87883734ff
MD5 8a28cd8457095908815cadf8244b549c
BLAKE2b-256 13d5d70295410cc20c4a6ee76940c1cb6ce037093735a415fd25414494201630

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.12-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 5502b83bdd209fc843d5fcfa69c0c0f9bcdb42a45a32b5e6e20aeb13b951a843
MD5 aa240d711e92b65e612161d599025a04
BLAKE2b-256 2a2bbaa6ad224b4177cef56782fba8e5c0a0032bd9355397e0619b780b4f426e

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