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

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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13manylinux: glibc 2.35+ x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 10.12+ x86-64

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

Uploaded CPython 3.12Windows x86-64

kglite-0.6.2-cp312-cp312-manylinux_2_35_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.35+ x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.12macOS 10.12+ x86-64

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

Uploaded CPython 3.11Windows x86-64

kglite-0.6.2-cp311-cp311-manylinux_2_35_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.35+ x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 10.12+ x86-64

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

Uploaded CPython 3.10Windows x86-64

kglite-0.6.2-cp310-cp310-manylinux_2_35_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.35+ x86-64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

kglite-0.6.2-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.6.2-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: kglite-0.6.2-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.6.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 533f3eb17a37a175ed184b9f33369dfc7e916ec16180b4c0b743256b82c47dd3
MD5 5ca8c1d8bee10ed4b853cfd3ab32d09d
BLAKE2b-256 fb2f2fb286e69cce5be1f918e7475f711af80c30dd5aa325a9e86a800043af6f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.2-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 8b938b73998bbe7a23aec323e6fce9b0ff29e57e84d45607e76c50fb68868e07
MD5 d55c9954a31215ad9287d355799c5c27
BLAKE2b-256 778887feeaa21bde12c1b58b59eec49caaa388df5a04055f2153323fc750955a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 442d612de559a0e752418d93b976db044b9884e861fbcfde2a4669e4362cc296
MD5 7c77553641666eb3a16ee491253876a3
BLAKE2b-256 f3611cdc32fcd0bd75eb1bf85b1b0f42f83fb78a0e842fc3f7c197176e56599c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.2-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ae1867523f09066db6b63cc61f09fab5352edc007b1f640f40d0dba72da56386
MD5 d6916e1ba90cd75dedb257ec57290921
BLAKE2b-256 27b14030730ccba98cb73cd22a2e894bdd0aaec3d5117abed1ea8c7dd57b108b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.6.2-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.6.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 9ce29d718c610a7fcfc4069ba685336c73000cab7cedac62809a578ff0bd057f
MD5 342c7e1254963715f9a2874f73961e42
BLAKE2b-256 0bff128b7cc37b68d9e0b8adc2fa786d978329eebeb317c5ee805e525142cc0f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.2-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 cc54417770e74b6176e28266904d986399efda154d1c45178438b0f60726f579
MD5 87df502d07ae7debb76f59a47aac6708
BLAKE2b-256 6aada53f8f88f7550a977dddb7328381ce25d93687983f5e260bbc7df5dc6edf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e8643a50f1e7dbf9fe38818718800dbe504132133a98e35e4e86bdfdef398e91
MD5 48a04c0e2923d120a4418bd9caf008a6
BLAKE2b-256 7c125430702c64e05691c7352e8a9a189b013be271310fab148379e0be67693b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.2-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 c1be53461b98bde2661b0934fbb04500d0112a96e2add00b80b2cf48f5983ca5
MD5 62db5f527d7ee1e441a5c83f75e0614a
BLAKE2b-256 14b14ff6a4ae80eda4e566da8ab064ac8edc43451a76120f14aa460c18266800

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.6.2-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.6.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 3a9e45d17bb03595799b4220c9ab893440abc30289c0e03980835aecfd3fed58
MD5 c35a54e20a470445eeb4b699ea59ad24
BLAKE2b-256 abe11a485273277915fe1baba8aaa44e9af570a8ca30fed3249ab82ff5b143cf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.2-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 f7c8064dd7e72e1b0b97bf4b66bd1de6da287fa6803ecc47307cb2b4d7f9127c
MD5 8efb36e510d94c9a2e5a5586106f9231
BLAKE2b-256 5e9ca03874595c85fec453d2237eb9ed625c5acc1f8e1e6817901625e21c3f98

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 221a25a69c309b4d92ec4bb0e302d5d850a5009122fb229b575a55303a3978ed
MD5 226789b2c53d18aaa2d82fb13d2481b4
BLAKE2b-256 ce5163090d59b21b2ea9e7b0637950b153dd56f83f4d554ce6ac21b392a9af6a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.2-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 8b09e2bed0742595aaaba7192195ef9e763a9622605f3de66d03203b80b2fb54
MD5 2a3887458c40054769bdaa33e73ed62f
BLAKE2b-256 2952de52ac18453c8b5558ade01ecd4dc6c55469c3add183020e0b9461437742

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.6.2-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.6.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 add1e208ffa766b3f15eafd63f2552a8d3026f837b8ea4e9b42432b2fdfbe950
MD5 e704bf733a988a879742cc0dba20d132
BLAKE2b-256 89d5fb5f1550a89e299454bdb4c136697a235194b22a7f79a257696d01026ed5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.2-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 7866df963dc3282a50c7fdfe9cdfb665bf2fe45c4e1ca74114e3af4a7f23ec29
MD5 766c554e3c4b818c1aec3788c7cce488
BLAKE2b-256 d97c63499bdc42f890f240acd8c975c2adbc63e607b4f8329992528949840b60

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3e79cdd869c602091a29405527184cf9c37c8e31afd9bed3d560700417cdef73
MD5 a9e90cea12a24a1058a70394af1a2438
BLAKE2b-256 7a661102f0f7bf120ddcec00a959e6d67addcafb0890baad0f76103bbc500e75

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.2-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 805544dc6d1d81e68ddb8488a2defdd4dbc20dfb09fe2c2b11c5a16bde65fc5b
MD5 9fb822ec5a6c9fbf389dd04dd975268f
BLAKE2b-256 434470fb9e37b7dce729514a5970671212c60881b1a44bd22273359fec48d562

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