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

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

Uploaded CPython 3.13Windows x86-64

kglite-0.7.1-cp313-cp313-manylinux_2_35_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.35+ x86-64

kglite-0.7.1-cp313-cp313-macosx_11_0_arm64.whl (3.0 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

kglite-0.7.1-cp313-cp313-macosx_10_12_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

kglite-0.7.1-cp312-cp312-win_amd64.whl (3.4 MB view details)

Uploaded CPython 3.12Windows x86-64

kglite-0.7.1-cp312-cp312-manylinux_2_35_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.35+ x86-64

kglite-0.7.1-cp312-cp312-macosx_11_0_arm64.whl (3.0 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

kglite-0.7.1-cp312-cp312-macosx_10_12_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

kglite-0.7.1-cp311-cp311-win_amd64.whl (3.4 MB view details)

Uploaded CPython 3.11Windows x86-64

kglite-0.7.1-cp311-cp311-manylinux_2_35_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.35+ x86-64

kglite-0.7.1-cp311-cp311-macosx_11_0_arm64.whl (3.0 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

kglite-0.7.1-cp311-cp311-macosx_10_12_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

kglite-0.7.1-cp310-cp310-win_amd64.whl (3.4 MB view details)

Uploaded CPython 3.10Windows x86-64

kglite-0.7.1-cp310-cp310-manylinux_2_35_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.35+ x86-64

kglite-0.7.1-cp310-cp310-macosx_11_0_arm64.whl (3.0 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

kglite-0.7.1-cp310-cp310-macosx_10_12_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.10macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: kglite-0.7.1-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 3.4 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.7.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 ee8b17c20bb66d561f0321913967a31ace5ac89a02bbfc72cf129e0d1d083103
MD5 410909a6fcbf3b7a97352320be654146
BLAKE2b-256 f0306fea507b92919af878786ac4d99d3d32d3bfcccfb7f5a695896a3ae6ed4b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.1-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 cf37d009a6cc56cf481e4f833120757f6ea2f73ccf0d37c560d1802fddef225c
MD5 d46b6f11686954d461790d97b60c1de2
BLAKE2b-256 6e44473f18740913d363853dbc3e66de183d2008d938a9e37709b2dce42d4799

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 39e57caa042a52948f2f62c919bb3322386178eb69028e55ff767fe935bb8af0
MD5 862165d5dba71015432512e2c4f72c96
BLAKE2b-256 453a8e30058e6be55ca6d8712e513a5d56d10f523c9d02613be0be6dcd1acd95

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.1-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 cf8b0088aeecffaa7234a19ecbda76dbfac5c268c0a8ada9c10ad0f05898bb6f
MD5 93434666b086aa14bd3cb00e321742bf
BLAKE2b-256 7833425cce7dccc5f0859e4d3c317aa6db9c25e32f8e149722001f2cf712e460

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.7.1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 3.4 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.7.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 4fd945fd3af0e7628bcacc6e14012d4b719b84169a73689ff040c21bc19611eb
MD5 62600753de42291eae9acccf5cd5fce1
BLAKE2b-256 b7340e53b7103e78e22c7138219fadc83f08efc15d9ba9ab1433b822775636b3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.1-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 4558ae45abeadb561646a37a0ae5a186b48a3ab67b71a4e2cbbc78242f3cc780
MD5 08235ef098356fa233aa70c6fbbc596d
BLAKE2b-256 61ff7471a9b55d0acead688d2cecd9a63ef512ce3d96e0e80fbd2aa12f15a675

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 45a8406bb9587d8cdfb947095e426047f2a257310649ad98af5d00388c78e247
MD5 b079231480931bc33857d9e4a6087774
BLAKE2b-256 cdd826bd0a0e512e5addbba3398b66ebf2ccea4589cab8456d1d1ce60e2d0eb3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.1-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 da9ac64c7967e1357468ecf6739c554a0419a50ceb4955985c45c1baef033a98
MD5 8138e363a850ab210bcf7fa00be905b0
BLAKE2b-256 bb460cabfb0f87328ca611518c2b858d2198527a579d7a5f4c2f4f899e5399db

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.7.1-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 3.4 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.7.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 ac7476b1ee6cfafb9695d10e6d4782e436a8ad1fa7f294b712e04e6f7932652e
MD5 9010589f68a19ed19b3be2b44c03edda
BLAKE2b-256 69d52e1480ed626491a0ba95eb9fa97c619ee1c92dd148792648e8471a420f32

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.1-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 25aa99334e52a45a60bf15098b0481f75da6cf146135130a27734e9f3ed5a4a9
MD5 58285cd9039ae6c1c2fefa1d10f01ec3
BLAKE2b-256 52a2cf6c2a5b92a56686960e38c869da0fc80916cd6999449de57584eca3fe15

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 09ba06fac1c4a9127e508a454fd9a04050eb8bf5dc9774539ef711a2e0a43ef3
MD5 4a40329d2f684e54f797ae0796f562e6
BLAKE2b-256 928c97f4d629b3fd9c0984c94aa1d6f57072af0cd3518255ba7e6b3d369f2bd6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.1-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 9d0ba594341ada22d9af0c6ea4e11cac2c7128dfa32e7494597c588b865c7dad
MD5 2bf72b3dc9cb878844a74e39a95f56f9
BLAKE2b-256 87396aecabdb9d0820e0408d9ce1dc2eef6f24d942c6aa53ba992de44176e478

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.7.1-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 3.4 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.7.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 bbd174e6c77ef9e775fe551b2f8c6e56ea48ef69bd1816950a839945ce7893d9
MD5 a99d16598b0f7675c50a2c170873d8ce
BLAKE2b-256 e08faf80f2f1625f7923843e2866bb1047f03b87a20f5d286f05d772a857638a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.1-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 f0d9da29edc9f2da51f099b285338f8c5d949af3891c9344197289f46aaed63c
MD5 b5a23e0d1108b1d49a7f59eba59069a8
BLAKE2b-256 8a6c5a84f00458d994e235ffe6f4c92aaf3e610b354011b4f042ac606ba66ca4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7fe2558182f7d8ff9adc0216a5e7b583dcdeff7e0f689eea3bc2af888f7ce023
MD5 a03b56acbcafb3620f06de5e604cba8f
BLAKE2b-256 892218c3739a5b21bd66ceb5741d04ea0b65563b1bbd77026b3666d17af24e69

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.1-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 11dada29d6cfada331f55e15189c448c4c656f9b8ce14096ae0ea88708f9a2e0
MD5 3fc0e9620d472581765f941ad234bcf6
BLAKE2b-256 863a63e29bdd98d6faa848fdb62b6f3a41c15e57277f95219643e4aac26692db

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