Skip to main content

High-performance in-memory graph database

Project description

FastGraph

Python Version License PyPI Version FastGraph is a high-performance, in-memory graph database engineered for Python applications that demand speed, low latency, and zero nonsense. Built for developers who want graph operations that actually keep up.

Created by BRAHMAI with ❤️ & ☕.


Key Features

  • High-performance adjacency-list engine with O(1) edge lookups
  • Memory-efficient internals and lightweight subgraph views
  • Automatic and manual indexes for ultra-fast queries
  • JSON/YAML configuration system with sensible defaults
  • Powerful CLI for common graph management tasks
  • Persistence support across msgpack, pickle, and JSON
  • Full thread safety for concurrent read/write workloads
  • Integrated performance monitoring and instrumentation

Quick Start

Installation

pip install fastgx

Basic Usage

from fastgraph import FastGraph

graph = FastGraph("my_graph")

graph.add_node("alice", name="Alice", age=30, type="Person")
graph.add_node("bob", name="Bob", age=25, type="Person")
graph.add_node("company", name="TechCorp", type="Company")

graph.add_edge("alice", "bob", "friends", since=2021)
graph.add_edge("alice", "company", "works_at", role="Engineer")
graph.add_edge("bob", "company", "works_at", role="Manager")

people = graph.find_nodes(type="Person")
print(len(people))

friends = graph.neighbors_out("alice", rel="friends")
print([n for n, edge in friends])

graph.save("my_graph.msgpack")

Configuration

FastGraph supports JSON/YAML configs for repeatable setups.

Example default configuration:

engine:
  name: "FastGraph"
  version: "2.0.0"

storage:
  data_dir: "~/.cache/fastgraph/data"
  default_format: "msgpack"

memory:
  query_cache_size: 128
  cache_ttl: 3600

indexing:
  auto_index: true
  default_indexes: ["id", "type", "name"]

performance:
  thread_pool_size: 4
  batch_threshold: 100

cli:
  default_output_format: "table"
  verbose: false

Usage:

from fastgraph import FastGraph
from fastgraph.config import ConfigManager

config = ConfigManager("my_config.yaml")
graph = FastGraph("my_graph", config=config)

CLI Tools

fastgraph create --name "social_network"
fastgraph import data.json --format json --save social.msgpack
fastgraph export social.msgpack --format json --output export.json
fastgraph stats social.msgpack --detailed --components
fastgraph config --show
fastgraph config --set storage.default_format=json

Advanced Capabilities

Indexing

graph.build_node_index("type")
graph.build_node_index("age")

people = graph.find_nodes(type="Person")
engineers = graph.find_nodes(role="Engineer")

stats = graph.get_index_stats()
print(stats["global"]["index_hits"])

Batch Operations

graph.add_nodes_batch([
    ("user1", {"name": "John", "age": 28}),
    ("user2", {"name": "Jane", "age": 32}),
    ("user3", {"name": "Bob",  "age": 25})
])

graph.add_edges_batch([
    ("user1", "user2", "friends"),
    ("user2", "user3", "colleagues"),
    ("user1", "user3", "acquaintances")
])

Subgraph Views

view = graph.create_subgraph_view(
    "people",
    lambda nid, attrs: attrs.get("type") == "Person"
)

print(view.node_count)
components = graph.traversal_ops.connected_components()

Traversal Algorithms

bfs = graph.traversal_ops.bfs("alice", max_depth=2)
path = graph.traversal_ops.shortest_path("alice", "bob")

for p in graph.traversal_ops.find_paths("alice", "bob", max_length=3):
    print(p)

Performance Monitoring

from fastgraph.utils.performance import performance_monitor

@performance_monitor("query_op")
def q():
    return graph.find_nodes(type="Person", age__gte=25)

monitor = graph.get_performance_monitor()
print(monitor.get_stats()["query_op"].avg_duration)

Testing

pip install fastgx[dev]
pytest
pytest --cov=fastgraph --cov-report=html

Development

Setup

git clone https://github.com/cognition-brahmai/fastgraph.git
cd fastgraph
pip install -e ".[dev]"
pre-commit install

Quality

black fastgraph tests examples
flake8 fastgraph tests examples
mypy fastgraph
pre-commit run --all-files

Benchmarks

FastGraph is tuned for high throughput and low latency.

Operation Complexity
Node lookup O(1)
Edge lookup O(1)
Neighbor query O(degree)
Indexed search O(log n)
Batch inserts O(n)

Detailed benchmarks live in benchmarks/.


Contributing

  1. Fork the repo
  2. Create a branch
  3. Commit your changes
  4. Push and open a PR

We keep contributions simple and frictionless.


License

MIT. See the LICENSE file.


Acknowledgments

FastGraph builds on proven graph database principles and a relentless focus on performance and developer experience. Thanks to all contributors and the Python ecosystem that made it possible.

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

fastgx-2.0.4.tar.gz (69.9 kB view details)

Uploaded Source

Built Distribution

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

fastgx-2.0.4-py3-none-any.whl (63.1 kB view details)

Uploaded Python 3

File details

Details for the file fastgx-2.0.4.tar.gz.

File metadata

  • Download URL: fastgx-2.0.4.tar.gz
  • Upload date:
  • Size: 69.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for fastgx-2.0.4.tar.gz
Algorithm Hash digest
SHA256 804513923d71958b2581d1f5116cb1d631f4cd5f253bc3330ecb5db1b2c80dd3
MD5 b5d37615d45f6db0a7eb478d826fb8db
BLAKE2b-256 653ab3f2184827e85c3e6c64d105a06f7a44c8700f8d8f1dfda4a6cb404fbaaa

See more details on using hashes here.

File details

Details for the file fastgx-2.0.4-py3-none-any.whl.

File metadata

  • Download URL: fastgx-2.0.4-py3-none-any.whl
  • Upload date:
  • Size: 63.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for fastgx-2.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 bbdc8caff12f67bb42e2f31da1cf55d7a273bf50b913ade5fe0974f73bd0b13e
MD5 0576e792c7ce06b8460638498c926575
BLAKE2b-256 a32574800393aada7b7358d205613f115861357962326a61fd0f590fe517aa2f

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