Skip to main content

Parse any codebase, build a knowledge graph, visualise it, and query it in natural language.

Project description

graphmy

Parse any codebase, build a knowledge graph, visualise it, and query it in natural language.

PyPI version CI License: MIT Python 3.10+

graphmy turns any source code directory into an interactive, queryable knowledge graph. Point it at a codebase and get:

  • A navigable graph — every function, class, method, and file as a node; every call, import, and inheritance as a typed edge
  • A self-contained HTML visualisation — open in any browser, share as a single file, no server required
  • Natural language queries — "what calls authenticate?", "find functions related to payment processing"
  • Multi-language — Python, JavaScript, TypeScript, Go, Rust, and Java in one tool

Install

pip install graphmy

For the --serve live UI:

pip install graphmy[serve]

For LLM-synthesized query answers (requires OpenAI key):

pip install graphmy[openai]

Quick start

# 1. Index a codebase (builds graph + vector index in .graphmy/)
graphmy index ./my-project

# 2. Query in natural language
graphmy query ./my-project "what calls authenticate?"
graphmy query ./my-project "find functions related to payments"

# 3. Generate interactive HTML visualisation (self-contained, ~2MB+)
graphmy viz ./my-project
open output.html

# 4. Or boot a live server with NL query bar
graphmy viz ./my-project --serve

# 5. Inspect codebase stats
graphmy info ./my-project

How it works

┌─────────────────────────────────────────────────────┐
│  PARSER  (tree-sitter, per-language grammars)        │
│  • functions, classes, methods, imports, inheritance │
│  • works on Python, JS/TS, Go, Rust, Java           │
├─────────────────────────────────────────────────────┤
│  GRAPH   (networkx DiGraph)                          │
│  • nodes: File, Class, Function, Method, …           │
│  • edges: CALLS, IMPORTS, DEFINES, CONTAINS,         │
│           INHERITS, IMPLEMENTS                       │
│  • persisted as JSON in .graphmy/                    │
├─────────────────────────────────────────────────────┤
│  SEARCH  (sentence-transformers + chromadb)          │
│  • embeds every symbol (name + signature + docstring)│
│  • incremental upsert — only re-embeds changed files │
│  • structural queries bypass embeddings entirely     │
├─────────────────────────────────────────────────────┤
│  VISUALISER  (cytoscape.js + dagre layout)           │
│  • self-contained HTML (no server needed)            │
│  • click any node → name, file:line, source preview, │
│    callers, callees                                  │
│  • --serve boots FastAPI + NL query bar              │
└─────────────────────────────────────────────────────┘

CLI reference

graphmy index   <path> [--exclude GLOB] [--fresh]
graphmy query   <path> <query> [--limit N] [--explain]
graphmy viz     <path> [--out FILE] [--serve] [--host H] [--port P]
                       [--max-body-lines N]
graphmy info    <path>
graphmy config  <path>
graphmy --version
graphmy --help

graphmy index

Parse the codebase and build the graph + vector index. Stores everything in .graphmy/ at the project root. Subsequent runs are incremental — only changed files are re-parsed.

graphmy index ./my-project
graphmy index ./my-project --exclude "tests/**" --exclude "**/*.min.js"
graphmy index ./my-project --fresh   # ignore cache, full re-index

graphmy query

Search the codebase in natural language.

graphmy query ./my-project "what calls validate_user?"
graphmy query ./my-project "find authentication functions" --limit 10
graphmy query ./my-project "explain the payment flow" --explain  # requires openai extra

graphmy viz

Generate an interactive visualisation.

# Self-contained HTML file (default)
graphmy viz ./my-project
graphmy viz ./my-project --out my-graph.html
graphmy viz ./my-project --max-body-lines 50   # cap inlined source for large repos

# Live server with NL query bar
graphmy viz ./my-project --serve
graphmy viz ./my-project --serve --host 0.0.0.0 --port 8080

Configuration

Create .graphmy/config.toml in your project root, or use environment variables:

# .graphmy/config.toml

# OpenAI integration (enables --explain in queries and the Explain button in --serve UI)
openai_api_key = "sk-..."
openai_model   = "gpt-4o-mini"   # default

# Paths to exclude from indexing (glob patterns, relative to project root)
exclude = ["tests/**", "docs/**", "**/*.min.js", "**/node_modules/**"]

# Maximum source lines inlined per symbol in static HTML (0 = unlimited)
max_body_lines = 0

Environment variables take precedence over config file:

export GRAPHMY_OPENAI_API_KEY="sk-..."
export GRAPHMY_OPENAI_MODEL="gpt-4o"

Python API

graphmy can also be used programmatically:

from graphmy import GraphmyIndex, GraphmyConfig

# Index a codebase
config = GraphmyConfig(exclude=["tests/**"])
index = GraphmyIndex("./my-project", config=config)
index.build()   # incremental by default

# Structural query — exact graph traversal
results = index.query_structural("authenticate")
for r in results:
    print(r.name, r.file, r.line)

# Natural language query
results = index.query_nl("what handles user authentication?")
for r in results:
    print(r.symbol.name, r.score, r.relationships)

# Export visualisation
index.export_html("graph.html")

Supported languages

Language Extensions Extracts
Python .py functions, classes, methods, imports, inheritance, decorators, async
JavaScript .js .mjs .cjs functions, classes, methods, ESM imports, require()
TypeScript .ts .tsx all JS + interfaces, type aliases, enums, implements
Go .go functions, methods on types, structs, interfaces, imports
Rust .rs functions, structs, enums, traits, impl blocks, use statements
Java .java classes, interfaces, methods, constructors, extends, implements

External symbols (calls/imports to dependencies outside the project root) appear as stub nodes — visible in the graph but not expanded. This keeps your graph focused on your code.


Index cache (.graphmy/)

<project-root>/
└── .graphmy/
    ├── config.toml          # optional user config
    ├── graph.json           # full graph (networkx node-link JSON)
    ├── file_hashes.json     # {filepath: [mtime, sha256]} for incremental re-index
    └── vectors/             # chromadb embedded vector store (SQLite + HNSW)

Add .graphmy/ to your .gitignore (graphmy does this automatically on first index).


Contributing

See CONTRIBUTING.md. Issues and PRs are welcome.


License

MIT — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

graphmy-0.1.3.tar.gz (313.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

graphmy-0.1.3-py3-none-any.whl (76.5 kB view details)

Uploaded Python 3

File details

Details for the file graphmy-0.1.3.tar.gz.

File metadata

  • Download URL: graphmy-0.1.3.tar.gz
  • Upload date:
  • Size: 313.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for graphmy-0.1.3.tar.gz
Algorithm Hash digest
SHA256 c4f715490ce1a550b02930250f02936ff191960169f1b6abff3beabc0ec446c8
MD5 111f75486492c23ddf8696b0c23a984e
BLAKE2b-256 757c52e73dee81679faf895a4ab3512cc6b381ae91928812e32c755383ce9141

See more details on using hashes here.

Provenance

The following attestation bundles were made for graphmy-0.1.3.tar.gz:

Publisher: publish.yml on Kamalesh-Kavin/graphmy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file graphmy-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: graphmy-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 76.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for graphmy-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a558dd603e15a90992997f0bea81082ffb3b03e72f3584dfaae0ef4f27914bec
MD5 00d5eb3ff59252209063a8ef728697cb
BLAKE2b-256 3503910aa177bf34593cbc34c8bac62d2eece3c347dc658a18fe888f99546352

See more details on using hashes here.

Provenance

The following attestation bundles were made for graphmy-0.1.3-py3-none-any.whl:

Publisher: publish.yml on Kamalesh-Kavin/graphmy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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