Skip to main content

PegaFlow Python Package

High-performance key-value storage engine with Python bindings, built with Rust and PyO3.

Features

  • PegaEngine: Fast Rust-based key-value storage with Python bindings
  • PegaKVConnector: vLLM KV connector for distributed inference with KV cache transfer

Installation

From Source

# Install maturin if you haven't already
pip install maturin

# Build and install in development mode
cd python
maturin develop

# Or build a wheel
maturin build --release

From PyPI (coming soon)

pip install pegaflow

Usage

Basic KV Storage

from pegaflow import PegaEngine

# Create a new engine
engine = PegaEngine()

# Store key-value pairs
engine.put("name", "PegaFlow")
engine.put("version", "0.1.0")

# Retrieve values
name = engine.get("name")  # Returns "PegaFlow"
missing = engine.get("nonexistent")  # Returns None

# Remove keys
removed = engine.remove("name")  # Returns "PegaFlow"

vLLM KV Connector

from vllm import LLM
from vllm.distributed.kv_transfer.kv_transfer_agent import KVTransferConfig

# Configure vLLM to use PegaKVConnector
kv_transfer_config = KVTransferConfig(
    kv_connector="PegaKVConnector",
    kv_role="kv_both",
    kv_connector_module_path="pegaflow.connector",
)

# Create LLM with KV transfer enabled
llm = LLM(
    model="gpt2",
    kv_transfer_config=kv_transfer_config,
)

Connector Modes

PegaKVConnector defaults to read_write: it queries PegaFlow for reusable KV blocks, loads matched blocks into vLLM, and saves newly computed full blocks back to PegaFlow.

Set pegaflow.mode to save_only when another vLLM connector is responsible for reads and PegaFlow should only persist KV blocks for later reuse. This is intended for MultiConnector decode-side setups where an upstream connector owns the external hit/load path, while PegaFlow records the resulting KV cache. In save_only mode, PegaFlow does not query or load KV blocks.

vllm serve Qwen/Qwen3-0.6B \
  --kv-transfer-config '{
    "kv_connector": "MultiConnector",
    "kv_role": "kv_both",
    "kv_connector_extra_config": {
      "connectors": [
        {
          "kv_connector": "<external-read-connector>",
          "kv_role": "kv_both"
        },
        {
          "kv_connector": "PegaKVConnector",
          "kv_role": "kv_both",
          "kv_connector_module_path": "pegaflow.connector",
          "kv_connector_extra_config": {
            "pegaflow.mode": "save_only"
          }
        }
      ]
    }
  }'

Valid values are read_write and save_only.

TP Shards Across Hosts

CUDA IPC is host-local. When one tensor-parallel replica spans multiple hosts, run one PegaFlow server on each host and configure the connector with every server endpoint in global TP-rank order:

{
  "kv_connector": "PegaKVConnector",
  "kv_role": "kv_both",
  "kv_connector_module_path": "pegaflow.connector",
  "kv_connector_extra_config": {
    "pegaflow.tp_shard_endpoints": [
      "http://host-a:50055",
      "http://host-b:50055"
    ]
  }
}

For TP8 and two endpoints, global ranks 0-3 register with the first server and ranks 4-7 register with the second. Each server sees a local TP4 topology and must manage the four GPUs on its own host. Every vLLM process must receive the same ordered endpoint list.

The scheduler queries every shard and only reuses the prefix available from all of them. Each worker loads with the lease issued by its local server. The connector gives every shard a distinct namespace, so deployments with a different host split cannot reuse an incompatible cache layout.

TP sharding currently requires equal contiguous shards and TP-only parallelism. Pipeline, decode-context, and prefill-context parallelism are rejected when more than one endpoint is configured.

P/D Partial Tail Blocks

vLLM normally exposes hashes only for complete KV blocks. In a P/D deployment, enable pegaflow.pd_tail_save on prefill and pegaflow.pd_tail_load on decode to reuse the final partial prompt block as well. Start both vLLM processes with the same explicit PYTHONHASHSEED and --prefix-caching-hash-algo xxhash_cbor.

Prefill: {"pegaflow.pd_tail_save": true}

Decode: {"pegaflow.pd_tail_load": true, "pegaflow.wait_for_full_prefix": true}

pegaflow.wait_for_full_prefix makes decode wait (up to 30s) until the full prompt prefix is fetchable from a remote node via MetaServer + RDMA. It only applies when prefill and decode run separate engines; it does not observe saves landing in a shared/local engine and has no effect when RDMA is not configured.

Development

See the examples directory for more usage examples.

Testing

Running Unit Tests

The test suite includes integration tests that verify the EngineRpcClient can correctly communicate with a running pegaflow-server instance.

Prerequisites

  1. Build the Rust extension:

    cd python
    maturin develop --release
    
  2. Build the server binary:

    cd ..
    cargo build --release --bin pegaflow-server
    
  3. Ensure CUDA is available (tests require GPU):

    python -c "import torch; assert torch.cuda.is_available()"
    

Running Tests

cd python

# Run all tests
pytest tests/ -v

# Run specific test file
pytest tests/test_engine_client.py -v

# Run with coverage
pytest tests/ --cov=pegaflow --cov-report=html

Test Structure

  • tests/conftest.py: Contains pytest fixtures for:

    • pega_server: Automatically starts/stops pegaflow-server for integration tests
    • engine_client: Creates an EngineRpcClient connected to the test server
    • client_context: Provides a ClientContext representing a vLLM instance with GPU KV cache tensors
    • registered_instance: Provides a registered instance ID for query tests
  • tests/test_engine_client.py: Integration tests for:

    • Server connectivity
    • Query operations with various inputs

Test Fixtures

The ClientContext class abstracts a vLLM instance and provides:

  • register_kv_caches(): Register GPU KV cache tensors with the server
  • query(block_hashes): Query available blocks
  • unregister_context(): Unregister context from server

Example test usage:

def test_query(client_context):
    """Test query operation."""
    result = client_context.query([])
    assert result is not None

License

MIT

Metadata

Release files for pegaflow-llm-cu13 0.24.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for pegaflow-llm-cu13 0.24.4
File
pegaflow_llm_cu13-0.24.4-cp314-cp314-manylinux_2_34_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.34+ x86-64 Details
pegaflow_llm_cu13-0.24.4-cp314-cp314-manylinux_2_34_aarch64.whl CPython 3.14 CPython 3.14 Linux glibc 2.34+ ARM64 Details
pegaflow_llm_cu13-0.24.4-cp313-cp313-manylinux_2_34_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.34+ x86-64 Details
pegaflow_llm_cu13-0.24.4-cp313-cp313-manylinux_2_34_aarch64.whl CPython 3.13 CPython 3.13 Linux glibc 2.34+ ARM64 Details
pegaflow_llm_cu13-0.24.4-cp312-cp312-manylinux_2_34_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.34+ x86-64 Details
pegaflow_llm_cu13-0.24.4-cp312-cp312-manylinux_2_34_aarch64.whl CPython 3.12 CPython 3.12 Linux glibc 2.34+ ARM64 Details
pegaflow_llm_cu13-0.24.4-cp311-cp311-manylinux_2_34_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.34+ x86-64 Details
pegaflow_llm_cu13-0.24.4-cp311-cp311-manylinux_2_34_aarch64.whl CPython 3.11 CPython 3.11 Linux glibc 2.34+ ARM64 Details
pegaflow_llm_cu13-0.24.4-cp310-cp310-manylinux_2_34_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.34+ x86-64 Details
pegaflow_llm_cu13-0.24.4-cp310-cp310-manylinux_2_34_aarch64.whl CPython 3.10 CPython 3.10 Linux glibc 2.34+ ARM64 Details

Total release size: 79.3 MB

Release files / pegaflow_llm_cu13-0.24.4-cp314-cp314-manylinux_2_34_x86_64.whl

Download URL pegaflow_llm_cu13-0.24.4-cp314-cp314-manylinux_2_34_x86_64.whl
Size 8.0 MB
Tags CPython 3.14 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
c0d9f95543fc54c87d83bb9dd61f7f4fcc1d5c37220a6f5c3daa09bb3fc2273a
BLAKE2b-256 checksum
How to use checksums
d30042a251eacb6358a8c5e848f7d3139f4536a3e0b203932cfa743308108115
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pegaflow_llm_cu13-0.24.4-cp314-cp314-manylinux_2_34_aarch64.whl

Download URL pegaflow_llm_cu13-0.24.4-cp314-cp314-manylinux_2_34_aarch64.whl
Size 7.9 MB
Tags CPython 3.14 Linux glibc 2.34+ ARM64
SHA-256 checksum
How to use checksums
afb3bdd0dfbb615ba8f907258ef4053f935534d198686fd7281e292befefd946
BLAKE2b-256 checksum
How to use checksums
573b2705f3b67c3617a1e85d10173e8f8d6603eafef54780d544f900ed6b6f82
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pegaflow_llm_cu13-0.24.4-cp313-cp313-manylinux_2_34_x86_64.whl

Download URL pegaflow_llm_cu13-0.24.4-cp313-cp313-manylinux_2_34_x86_64.whl
Size 8.0 MB
Tags CPython 3.13 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
e16323c82c7c9be61abb97f422a4ce8aa5f12738b54a9d32696320bddadc6f7d
BLAKE2b-256 checksum
How to use checksums
9082035275bd7e2bc777db993cfe6cc557ea58603fe51993504e67dfead05501
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pegaflow_llm_cu13-0.24.4-cp313-cp313-manylinux_2_34_aarch64.whl

Download URL pegaflow_llm_cu13-0.24.4-cp313-cp313-manylinux_2_34_aarch64.whl
Size 7.9 MB
Tags CPython 3.13 Linux glibc 2.34+ ARM64
SHA-256 checksum
How to use checksums
68432f4138c6369fce982d2743cbed8dc7d71f5a767602eae4b0d2f202aa0f0f
BLAKE2b-256 checksum
How to use checksums
b8b103e29adfe608476184cf01c28920e7380b8c21a0890a0f3687514b6bb73d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pegaflow_llm_cu13-0.24.4-cp312-cp312-manylinux_2_34_x86_64.whl

Download URL pegaflow_llm_cu13-0.24.4-cp312-cp312-manylinux_2_34_x86_64.whl
Size 8.0 MB
Tags CPython 3.12 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
6e2637ee62c52ce55766a96f275020453f71ffcb0307bb8fdab8118816008330
BLAKE2b-256 checksum
How to use checksums
9314ac27cff2196dcb3bf977fedf41063930730195d110f23ded294c808dc4e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pegaflow_llm_cu13-0.24.4-cp312-cp312-manylinux_2_34_aarch64.whl

Download URL pegaflow_llm_cu13-0.24.4-cp312-cp312-manylinux_2_34_aarch64.whl
Size 7.9 MB
Tags CPython 3.12 Linux glibc 2.34+ ARM64
SHA-256 checksum
How to use checksums
408944e33fe68a9cd62084806ae4c2c6cf39d1d46a59218422e879c57dd12bdb
BLAKE2b-256 checksum
How to use checksums
77c9e3b6ae575e37c30cdb90d46e441f617a2a4e61d165a4ece68ccc52194d34
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pegaflow_llm_cu13-0.24.4-cp311-cp311-manylinux_2_34_x86_64.whl

Download URL pegaflow_llm_cu13-0.24.4-cp311-cp311-manylinux_2_34_x86_64.whl
Size 8.0 MB
Tags CPython 3.11 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
5c4805d2d55547458fe4b7fbd38069b106c34d644366b83573b935953dcc12d5
BLAKE2b-256 checksum
How to use checksums
55bc04c92808a79d44c9db56703a2d9aac0f0c7d07d56c9d518840cb76dce046
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pegaflow_llm_cu13-0.24.4-cp311-cp311-manylinux_2_34_aarch64.whl

Download URL pegaflow_llm_cu13-0.24.4-cp311-cp311-manylinux_2_34_aarch64.whl
Size 7.9 MB
Tags CPython 3.11 Linux glibc 2.34+ ARM64
SHA-256 checksum
How to use checksums
63710ea49d746fcda9aea02d3935561522ffb91d4b0c8bf9513473cfd4b309a6
BLAKE2b-256 checksum
How to use checksums
42a578b59695691e795a587d3b30a5060bf2c32b4aa68083f4ada2d0d2ecfbe1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pegaflow_llm_cu13-0.24.4-cp310-cp310-manylinux_2_34_x86_64.whl

Download URL pegaflow_llm_cu13-0.24.4-cp310-cp310-manylinux_2_34_x86_64.whl
Size 8.0 MB
Tags CPython 3.10 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
030bfe7fb9eb32c3b0ca38f8c3453b54b00ae8bbe12b6ebdbfe3f7370b55bd01
BLAKE2b-256 checksum
How to use checksums
23e74f9dcc454e078f1b2b7aac7c609837c2e7deefdb292d929852bf6449dfcd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pegaflow_llm_cu13-0.24.4-cp310-cp310-manylinux_2_34_aarch64.whl

Download URL pegaflow_llm_cu13-0.24.4-cp310-cp310-manylinux_2_34_aarch64.whl
Size 7.9 MB
Tags CPython 3.10 Linux glibc 2.34+ ARM64
SHA-256 checksum
How to use checksums
e7f7df91eceee3274d3e35524cf3a6b93f326fd0d1dfdfe668e4b7be8f4d2497
BLAKE2b-256 checksum
How to use checksums
7a4907831e8b33a812834149fbfdab175271b219968fc893e401c41ab4f1595c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for pegaflow-llm-cu13 0.24.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.24.4 This release

10 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page