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

Uploaded CPython 3.13Windows x86-64

kglite-0.6.5-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.5-cp313-cp313-macosx_11_0_arm64.whl (2.9 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 10.12+ x86-64

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

Uploaded CPython 3.12Windows x86-64

kglite-0.6.5-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.5-cp312-cp312-macosx_11_0_arm64.whl (2.9 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.12macOS 10.12+ x86-64

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

Uploaded CPython 3.11Windows x86-64

kglite-0.6.5-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.5-cp311-cp311-macosx_11_0_arm64.whl (2.9 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 10.12+ x86-64

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

Uploaded CPython 3.10Windows x86-64

kglite-0.6.5-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.5-cp310-cp310-macosx_11_0_arm64.whl (2.9 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

kglite-0.6.5-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.5-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: kglite-0.6.5-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.5-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 aeea4db6c630d2d45bd5489b683d91d88311c961e1c9fcb19eb513105bd1abb5
MD5 e95623cec3fc0c5f69d7c3d22f59064f
BLAKE2b-256 8456223762f8997cfbe5a0960e81fefd373384d3ca85e230aa8faec8ddd3fd51

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.5-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 b18c13e8e87e8f627fae18ce06ebab2cb0a84b5cc06a047a388aa362ec8456cb
MD5 e34f79dcf107758784316f4d32853257
BLAKE2b-256 7f9e7c3490270e3b2aa00c148bd02010aa3d8b7a294729a89a936394f43be0b6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.5-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 36010d710d10b672eefb17705e092494d11abe25cfe5119f03b80c544256ed41
MD5 25006fc7302831b301d3da961c9a27e3
BLAKE2b-256 69e60148376827a5d1d1f83d744010c86a391b0aab86f5d2183b37e19e31e0a5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.5-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 969245d178ffb7c42b7d962b544aec8cdea0f9ba2283a26b00506ac05cc246eb
MD5 f9b3bd4a606906e2617cd22d7c930860
BLAKE2b-256 2f6fc718e9e02f753e910b2d07a9199fedd9b1fbcf2950461d9655b28a499f60

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.6.5-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.5-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 8d8821dfa04e669ba8dfa952d5af453eb059a4ee4a42baa9d1261d6b7aaf3b8f
MD5 9101401959e80ceb9bce6f6182d32d12
BLAKE2b-256 a3b6eecf86753454c858243eaeda7529cd9de9e5f597a50065e99e5b3a06f642

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.5-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 f4d709f70d17c19e16281414244aeca34ef78a5509d1bc20fa5aaa982adc7d56
MD5 773d01863c597516dc6e6be017b6542a
BLAKE2b-256 b13bbd8b3fbbf72bd152dc53d94b1a154c81be530b1dbd7d27202b260434eea2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.5-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b13d241a80311e7a24bae08d6e7613a1917273c3c385c34d6ba1bca7b3fb81af
MD5 8d13238fc88985c1e38947f7bb291626
BLAKE2b-256 b42993bd53196d8d5a133b8868fb1605dca444b7136a18223cbec97330c6130c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.5-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 af44302f40fcff102ef5ca008173ca345c0ed1b710eb8bbbc0ccbb8e1209b4d0
MD5 4a26fec7e21dbc727c7f8e2835fade2d
BLAKE2b-256 d2044216df61a10f4190ab2189ec4d364e519cc611a6cf67ce0247439e8115fd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.6.5-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.5-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f2b7659288088c809c327e55f49177752078fa04b51617e71d2880991006ade4
MD5 235855f54e3b7f9742ddc949faeacbd6
BLAKE2b-256 524b41592351c735d000be56a3f52d79135babdad8c0efce1bfdbfc21306a26c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.5-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 c11e61ca287d1b4845900bb4814a6b9f94bcb1d24abef52baa95fcbbcd2edc78
MD5 5b82684ba352a7d1f96f3700561894e8
BLAKE2b-256 1665c687d670bf7a7474ada659ba0f5a71176d9d3cdabf81c6620d43dbc8449e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.5-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d36b0f82bc3bca5e299387ec6ff354703285c9ffda168cc709ab8010ab5dfa68
MD5 f881ab832e72e4bca300983c1dc28d69
BLAKE2b-256 4b841a2c5757c7cab5d30dec05e65e9ef51490eaa4332c3e17c4dac9e6f7da24

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.5-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 21dadc68613c823f36e0470d3ff3879b21016c937b8bfb9f0053decff96e3761
MD5 7c4e27a4fd5a20fb800400c898279704
BLAKE2b-256 3023fa51a48a010797bc25a8e599ea56958b32320e0d64bb47a6cd8868628401

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.6.5-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.5-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 7c3b4b3ae895b67818fc7f1fb736b028599200690d37a6226622794f7501989a
MD5 daaa204ffb5d131dc91faaf2c8dd421a
BLAKE2b-256 92d88f8583dbeee3d56eb14948c9b34fbb9f5ea2ac4103983dafed0709aefc36

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.5-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 ffede424e282f742e0cacbed1f50c280541e239d5a5fa1a1eedec685bbaff84a
MD5 3518ef05133a71d3392ac7ae5c7d3d6f
BLAKE2b-256 37ef012957a90fedbb2d3d56dc84b9209b4a876417b000369f363dd7c69a753a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.5-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5e1559eb7fc04d162df04c6b7b6d0402eb63c1d23e9dfe4fb7d805da3dfb62aa
MD5 9dc15940eac5ddd069a263caadc92dd1
BLAKE2b-256 24dff51dcc8d1c83e05ea1a6f0b59097a5b6c2775871d05145a00d1082aa4131

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.5-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 33ce5193626e930c59f34c6b3a08d62e1ffcf8c50524ef31432a8d5968ae1ade
MD5 b169ce6b61801eaf88020f139f1ec2b5
BLAKE2b-256 8022c9d2b9a37c1949e86858d0c24cfffeff67e9e3502c2f35701485a220682b

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