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

Uploaded CPython 3.13Windows x86-64

kglite-0.7.14-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.14-cp313-cp313-macosx_11_0_arm64.whl (3.3 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 10.12+ x86-64

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

Uploaded CPython 3.12Windows x86-64

kglite-0.7.14-cp312-cp312-manylinux_2_35_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.35+ x86-64

kglite-0.7.14-cp312-cp312-macosx_11_0_arm64.whl (3.3 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.12macOS 10.12+ x86-64

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

Uploaded CPython 3.11Windows x86-64

kglite-0.7.14-cp311-cp311-manylinux_2_35_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.35+ x86-64

kglite-0.7.14-cp311-cp311-macosx_11_0_arm64.whl (3.3 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 10.12+ x86-64

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

Uploaded CPython 3.10Windows x86-64

kglite-0.7.14-cp310-cp310-manylinux_2_35_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.35+ x86-64

kglite-0.7.14-cp310-cp310-macosx_11_0_arm64.whl (3.3 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

kglite-0.7.14-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.14-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: kglite-0.7.14-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.14-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 a241389876f4e37c31300a908168e9cbb7fcb4601433ff7388736f082beec7ea
MD5 4a6ed2db43e9e1ab5f3d3fb76f070c43
BLAKE2b-256 3583c46d6af007cbf050f277660c70860a6c0737d9241508d93d958af32b49dc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.14-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 9a1c74dbcd2a91b7b2c1c536826831218c9c8ca8dae1db0087e96a1a90b2fd2e
MD5 7c461dea376f7b8f051bada38adea51d
BLAKE2b-256 8477f0c282dbac6db6af0e43b59f0ce031a87d9b3e95b0ec7d7cabf54b4b811e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.14-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 31885d0ea41b820511305b7a2ea2a8a7513279f405d77298dfe361fe048b6747
MD5 363f431045f9b9704068f43200564e95
BLAKE2b-256 c3b198307b343ce73c25cf21a13c6adc2d74a70cf797dc7d3b2344f614976da2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.14-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b4bcee3fa80e8bfb57a83307cc4aa4c0ff9581e97bbc6334d774af62bdbdca5b
MD5 43fdaba28f1323f7faf6b661adf9a5d0
BLAKE2b-256 360a40e3d5947168bba8d2c10128df635a628d2120e61e549f7f7dfbd8c5f487

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.7.14-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.14-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 b640b860c35c90f023985ce9bdbc19ac9d79a0de59b7984913950173c9856250
MD5 187e2960d6ef22d67cc81d0ae4ae0a36
BLAKE2b-256 e4d24879f955ab5fd63c88762706e3563deec1b4cefcf77868315b89d152f788

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.14-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 75edd7ec59d50ea26d0a998ea4f40275aedb6d11cdefe23485548f1cc25c6490
MD5 be6f27e6fd857b66e2b2d92900b149be
BLAKE2b-256 559b1762372e70d6b67c1fefdfd3c1bc8916c5d679b268c02355ab4ae371ef5a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.14-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1b8aca7840c8c73aa013b58cc4d5b5cc18c00d0ea342ea4c83ee405732888b2f
MD5 6cf45009ac258f5c346ad9dd3a6b5090
BLAKE2b-256 16fa948979262863eb93826f1f17a9da4e2db456c6ce2b50e62997ffdd91062d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.14-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 56262f1bd4c860cabe8d7ef3740dcde16c34985e24507418186f4fbfd635c0f5
MD5 f80c5fde66b4498cab9d6963eb074597
BLAKE2b-256 4836bbd2591c6fc52accca279fc956a62fd36249c4c7fb177e2689047a3d1e33

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.7.14-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.14-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 b8cd362ce634e2a96b8de90b7427f962fcb5ee8deacc31062cdebb6bb74c2758
MD5 516792c573801d287ad3ab018223d1fe
BLAKE2b-256 2eee759206228f84df6c0abc009da49d42567f59d9e39493698efbcb5228775f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.14-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 f05a4f66102e78690aa3bc2e4b0c68c871da2c7b512e5cd3e94487830cb166cb
MD5 bc8764a9d75a2ff1ca7b19a2e733fca8
BLAKE2b-256 7fb8074d4b03b6009d2edd7626f7657e379566ec909f2018817792b75419d40f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.14-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 50f63a3179cc6eaed3889f93f84218ee83f7a8bb035929b03a8078905a73fe70
MD5 00e731b8cbb7b3905e98afa17dd55147
BLAKE2b-256 5e444ed4fd0cc71eeadde7255969d4f57109e0d91547c92299f0227e4f578bf8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.14-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 6127d2e298dbe383e023411ca8733bb388b33527bfaeb141b545349bca13edcc
MD5 b07ef3378fbabb0ba9cad8c1410ef009
BLAKE2b-256 f59f9ecf4a3f571e58b4e89dcb5471b8d0931102a69b66e73f209fd8b9eddabf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.7.14-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.14-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 16349e8f32edb6804b142b3658162a6f86403cfffa4d54e09ae97fcb08a9692c
MD5 c5909c877e1a9a74b54261aa3a55804d
BLAKE2b-256 b9d2a01c2929efc7b88f1bf684dd0a9943e3b49dd463754da2f39adfc7ee2387

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.14-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 8f627de9816062b2e955dbf1bf5ff856591e6c59f43059ff9593704e32b7fdca
MD5 77c7b2e42c053c2ac7c66554144e1fae
BLAKE2b-256 7c6dd369a9d2677d59422e562d9baca2d61dca656f08b44579570fdc4d5a40a2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.14-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d13badc8b8f751aacaf74a9ead80ec940f3242ad76a89d86f6184c298e0346df
MD5 89ef27ce5eea0af0b4c77958f5532188
BLAKE2b-256 5fc67e7d9e1096d389bd465fb07fc41b301c337aff9c3bbe6f9ccbb763939965

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.14-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 79f32e444e0423d20ae5ffd127e89deb6a076268926727c25e9fe545088faa0a
MD5 5ea71ea0a31d882ccfaec1d84fb6043c
BLAKE2b-256 0741efc2de260b247cb6d18d4f4155ac1d835938904501c7c7856b7a84a45bdc

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