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

Uploaded CPython 3.13Windows x86-64

kglite-0.5.89-cp313-cp313-manylinux_2_35_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.35+ x86-64

kglite-0.5.89-cp313-cp313-macosx_11_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

kglite-0.5.89-cp313-cp313-macosx_10_12_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

kglite-0.5.89-cp312-cp312-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.12Windows x86-64

kglite-0.5.89-cp312-cp312-manylinux_2_35_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.35+ x86-64

kglite-0.5.89-cp312-cp312-macosx_11_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

kglite-0.5.89-cp312-cp312-macosx_10_12_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

kglite-0.5.89-cp311-cp311-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.11Windows x86-64

kglite-0.5.89-cp311-cp311-manylinux_2_35_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.35+ x86-64

kglite-0.5.89-cp311-cp311-macosx_11_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

kglite-0.5.89-cp311-cp311-macosx_10_12_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

kglite-0.5.89-cp310-cp310-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.10Windows x86-64

kglite-0.5.89-cp310-cp310-manylinux_2_35_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.35+ x86-64

kglite-0.5.89-cp310-cp310-macosx_11_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

kglite-0.5.89-cp310-cp310-macosx_10_12_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.10macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: kglite-0.5.89-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 3.1 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.5.89-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 8d0c154e3a64dd9d617d548c75234a7e561cfa60e3a0ff946246a94f177f81ab
MD5 8b375455d4f5c66294aaa56d5d0d310e
BLAKE2b-256 314acc184c7a0d33eabde2a79f5d9647dc059870c34c49924c798e0b36a97229

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.5.89-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 9f0ed13b72de312816be74488b93b9029c84d915e2174cc5f7c12e923b9905d5
MD5 aade36e5259e709733084771c5e81aa9
BLAKE2b-256 abaed76b7ef7bfc93e8af0604a4a98f646cfdb4ffb6389840141c2ae19d9ab97

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.5.89-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0904b5ea2feb4c68edd0f557b9bf3f75cea58a25146f6ac4f360d89b8ae41adc
MD5 21894dfd8d9107e1495b7ff20e61174d
BLAKE2b-256 497fb18c371d57997f74ab14ba376240bda04e91e99b4ac669d4f4685200478b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.5.89-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 0e179cb9b7675b2f3c23518a352d28aa82c5ab9dbe3bcde4a32d2bce0492290d
MD5 c2ab83e29eba5a13027e35dee17ab23d
BLAKE2b-256 819394024d29bb7ed105297f7aeb267798a42dd772cb600fd3da029d9ffb7bad

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.5.89-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 3.1 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.5.89-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 5b2c902ac399aaa7de6dfd1489a67861d3dc32c54c3180d24ea592ee1c1466b9
MD5 05ba948719ce7391859ba6e6c1f2ce2b
BLAKE2b-256 ff3a210be6ca718fd999b3f6d8a2405ca85ddb9278900d496802d5a69f9ad5c7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.5.89-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 7dbdc3ebc844fd0a4a46618a72718e63d190d86c6ffb6d5d583ca0315834395a
MD5 6d34a4bb56c20c6242a93df4cf1e5513
BLAKE2b-256 24e5aa5b4867346579369ad5d720fd71837ed31653f2616ddf4e79b27bd6a202

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.5.89-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c6aed1dc6095416a422deca2fb9de63f8cbfec959af98ac0eadb7d401b184b40
MD5 fc52575ca9f8a0d00d84f71df7de936b
BLAKE2b-256 775d2986f5cb54800f897bc2cd9672653bd236f10956360d5e0cb768df321aab

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.5.89-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 0fc697bb807268335da289460afe061348a2aa6e92662038866e6c5c1522ff31
MD5 dd4765b81b5ddd3f6a99c01ab77ecb21
BLAKE2b-256 2e1ce1a4a8dfa6630c16ed365a20acba1bf6109162650e41f45579294c856ee7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.5.89-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 3.1 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.5.89-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 c9288a6784c1521226262115a98b50d7ad8a72bd3b90050bacd80a48fad9054e
MD5 20e974a94a83acbd860145be5ac9a9e7
BLAKE2b-256 500a637ac34792463ae45752b8ae02746f9a514abe847439cfbe548a4e79d43e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.5.89-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 6d57c0a9d75ee4b797d5a5c437e1d6cfa11e6d289915fb791c9f68eb95b73f6a
MD5 7d526ce09aaeff3d82d03f8f216474e9
BLAKE2b-256 8dbc927350252499927c74bfffc4ed51d8a2dc0734942bc3d126b39f8c8f23d9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.5.89-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6015ae624c2a2f6026f5685780e7a4584ce253af70a0c852d64386fea139ebcc
MD5 0f89ae1207adbc695917c03af61847c0
BLAKE2b-256 07fd86243fd086c589a669a28d3fb2ae278641a8155e4450c397919bf5b315be

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.5.89-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 6b767eaad63aa22737bb5131b4557aeb4a6b828dfcbfefb0784bbac23d2a2696
MD5 e6a07e6811e66b5367057655b84e9d36
BLAKE2b-256 5e1564fd15fd9624a1b71b21adaeb0162386cfed4b6ec80a6c9699aebe2a172b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.5.89-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 3.1 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.5.89-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 d3b5510d04ec338c19042514c521256252fc25ecde49dc3d01ec320943e73f69
MD5 151bf73839b189eb3b1a723f5adae52f
BLAKE2b-256 0e07b5c9d60b5ba86db248a1c2bed5f399fccdba61b618a27a18dc81facf504f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.5.89-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 40d544d46f849bbd4d2f9142f0ac042092754ae7da2c59c2bcfaba412f1b1a77
MD5 2542abebb6410a4477098f5b21a8ca63
BLAKE2b-256 f8b9606687db51dede9951cd4b23db41afbff83312cbdbb710cb5ead7cb1c1cb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.5.89-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 231931b114f536fe20f70a80b4bcf4841c8ddf5d182b205287b9def1e6f0ef0f
MD5 f642491820250f661c1205417c9c9e6c
BLAKE2b-256 2048189b20ad7d50f5238883fc7cd5ccfc52185cf13c25a11fb8bdfb333f16d5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.5.89-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 943152755d08e930866d99e74f6de9fb323db124b799b1b382299dfa53628c19
MD5 8678bd58e34ca122e96735f4073ff475
BLAKE2b-256 42742307e5a97c5e9e1c0140f438c492ee69a5ba87a50acfce2a3d93c2cea428

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