Skip to main content

⚡ B-FAST (Binary Fast Adaptive Serialization Transfer)

CI Documentation PyPI version Python versions npm version License: MIT Performance CodSpeed

B-FAST is an ultra-high performance binary serialization protocol, developed in Rust for Python and TypeScript ecosystems. It's designed to replace JSON in critical routes where latency, CPU usage, and bandwidth are bottlenecks.

"Performance is not just about speed—it's about efficiency where it matters most"

B-FAST was born from the recognition that modern applications need more than just fast serialization—they need smart serialization that adapts to real-world constraints. After extensive optimization, B-FAST operates in the sub-microsecond realm (676 ns encode / 754 ns decode for 100 objects), achieving 4.1x faster than orjson for objects, 5.7x faster on slow networks, and over 3,100,000 frames/s in streaming protocol.

Philosophy: We believe that the future of data transfer lies not in raw CPU speed alone, but in intelligent protocols that minimize network overhead while maintaining excellent performance. B-FAST represents our contribution to a more efficient, bandwidth-conscious web.

📚 Documentation

Full documentation available at: https://marcelomarkus.github.io/b-fast/

🚀 Why B-FAST?

  • Rust Engine: Native serialization without Python interpreter overhead.
  • Sub-Microsecond Latency: Encodes 100 structured objects in 676 ns and decodes in 754 ns.
  • Pydantic Native: Reads Pydantic model attributes directly from memory, skipping the slow .model_dump() process.
  • Zero-Copy NumPy: Serializes tensors and numeric arrays directly, achieving 14-96x speedup vs JSON/orjson.
  • Parallel Compression: LZ4 with multi-thread processing for large payloads (>1MB).
  • Cache Optimized: Aligned allocation, direct C-API lists, interned strings, and zero intermediate copies.

📊 Benchmarks (State-of-the-Art Results)

⚡ Sub-Microsecond Realm (100 Structured Objects)

Operation Time (ns) Equivalent Ops / Second Speedup vs Baseline
Encode (100 objects) 676 ns > 1,470,000 ops/s 🚀 2.1x faster
Decode (100 objects) 754 ns > 1,320,000 ops/s 🚀 2.6x faster

🚀 Simple Objects (10,000)

Format Time (ms) Speedup
JSON 12.0ms 1.0x
orjson 8.19ms 1.5x
B-FAST 2.01ms 🚀 6.0x

B-FAST is 4.1x faster than orjson!

🌊 Streaming Protocol (1,000 frames)

Metric Performance Speedup / Throughput
Streaming Decode (Aligned) 0.31ms (314µs) ~3,180,000 frames/s (145x vs NDJSON)
Streaming Decode (Fragmented) 0.32ms (322µs) ~3,100,000 frames/s (Zero TCP penalty)
Single Frame Latency 2.0ns Real-time instant parsing
Sustained Stream Throughput > 3,100,000 frames/s Ultra-high-frequency telemetry & AI feeds

🔄 Round-Trip (Encode + Network + Decode)

Complete test including network transfer and deserialization (10,000 objects):

📡 100 Mbps (Slow Network)

Format Total Time Speedup vs orjson
JSON 114.5ms 0.8x
orjson 91.7ms 1.0x
B-FAST + LZ4 16.1ms 🚀 5.7x

📡 1 Gbps (Fast Network)

Format Total Time Speedup vs orjson
JSON 29.4ms 0.5x
orjson 15.3ms 1.0x
B-FAST + LZ4 7.2ms 🚀 2.1x

📡 10 Gbps (Ultra-Fast Network)

Format Total Time Speedup vs orjson
JSON 20.9ms 0.4x
orjson 7.7ms 1.0x
B-FAST + LZ4 6.3ms 🚀 1.2x

🎯 Ideal Use Cases

  • ⚡ Microservices & High-Frequency Trading: Sub-microsecond latency (< 800 ns per 100 objects)
  • 🌊 Real-time Streaming & AI Telemetry: > 3,100,000 frames/s with zero TCP fragmentation penalty
  • 📱 Mobile/IoT: 89% data savings + 5.7x performance on slow networks
  • 🌐 APIs with slow networks: Up to 5.7x faster than orjson
  • 📊 Data pipelines: 14-96x speedup for NumPy arrays
  • 🗜️ Storage/Cache: Superior integrated compression
  • 🚀 Simple objects: 4.1x faster than orjson

📦 Installation

Backend (Python)

# Basic installation
pip install bfast-py

# With FastAPI support
pip install "bfast-py[fastapi]"

or with uv:

uv add bfast-py
# or
uv add "bfast-py[fastapi]"

Frontend (TypeScript)

npm install bfast-client

🛠️ How to Use

Backend (Python)

1. FastAPI Integrations ⭐

B-FAST supports two integration styles for FastAPI:

Option A: Transparent Content Negotiation (BFastMiddleware)

Zero-code route refactoring. Existing routes return JSON by default, but automatically return compressed B-FAST binary when requested by clients via Accept: application/x-bfast:

from fastapi import FastAPI
from b_fast.fastapi import BFastMiddleware

app = FastAPI()
app.add_middleware(BFastMiddleware, compress=True)


@app.get("/users")
def get_users():
    # Returns standard JSON to browsers
    # Automatically returns B-FAST binary when requested via Accept: application/x-bfast!
    return [{"id": i, "name": f"User {i}"} for i in range(1000)]
Option B: Direct Route Integration (BFastResponse & BFastStreamingResponse)

Explicit route control without middleware:

from fastapi import FastAPI
from pydantic import BaseModel
from b_fast import BFastResponse, BFastStreamingResponse

app = FastAPI()


class User(BaseModel):
    id: int
    name: str


# 1. Explicit B-FAST binary response
@app.get("/users", response_class=BFastResponse)
async def get_users():
    # Returns binary B-FAST data with automatic LZ4 compression
    return [User(id=i, name=f"User {i}") for i in range(1000)]


# 2. ⚡ Streamable HTTP (Progressive Chunks, 3.18M frames/sec)
@app.get("/users/stream")
async def stream_users():
    async def user_generator():
        for i in range(1000):
            yield User(id=i, name=f"User {i}")

    # Streams framed chunks with Content-Type: application/x-bfast-stream
    return BFastStreamingResponse(user_generator())

2. Django Ninja & Django

from ninja import NinjaAPI
from b_fast.django import BFastRenderer, BFastHttpResponse

# Django Ninja with BFastRenderer
api = NinjaAPI(renderer=BFastRenderer())

@api.get("/users")
def get_users(request):
    return [{"id": i, "name": f"User {i}"} for i in range(1000)]

# Standard Django View
def django_view(request):
    return BFastHttpResponse({"status": "ok"})

3. Polars & Pandas DataFrames

from b_fast import BFast, encode_dataframe
import polars as pl

df = pl.DataFrame({"id": [1, 2, 3], "score": [95.0, 88.0, 92.5]})

# Direct native serialization in BFast
packed = BFast().encode_packed(df, compress=True)

# Or with orientation control ('records', 'columns', 'split')
col_data = encode_dataframe(df, orient="columns")

4. FastMCP 2.0 (AI Agent Tools)

from b_fast import FastMCPBFast, bfast_tool

mcp = FastMCPBFast("data-service")

@mcp.tool()
@bfast_tool()
def query_records(limit: int = 100):
    return [{"id": i, "metric": i * 1.5} for i in range(limit)]

Frontend (TypeScript)

1. Fetch & TanStack Query (React Query)

import { bfastFetch, bfastQueryOptions } from 'bfast-client';
import { useQuery } from '@tanstack/react-query';
import { z } from 'zod';

const UserSchema = z.object({ id: z.number(), name: z.string() });
type User = z.infer<typeof UserSchema>;

// Direct Fetch
const users = await bfastFetch<User[]>('/users');

// In React with TanStack Query
function UserComponent() {
    const { data: user } = useQuery(
        bfastQueryOptions<User>({
            queryKey: ['user', 1],
            url: '/users/1',
            schema: UserSchema, // Runtime schema validation
        })
    );
    return <div>{user?.name}</div>;
}

2. Streamable HTTP (Progressive Stream)

import { decodeReadableStream } from 'bfast-client';

async function streamData() {
    const response = await fetch('/users/stream');
    
    // Iterates over incoming network frames in real-time
    for await (const user of decodeReadableStream(response.body!)) {
        console.log('Received user in real-time:', user);
    }
}

🤖 AI Assistants & Coding Agents (llms.txt)

B-FAST provides a standardized, curated llms.txt endpoint for AI tools (OpenCode, Cursor, Claude Code, ChatGPT, Windsurf, and GitHub Copilot).

Prompt your AI assistant directly:

Follow the B-FAST guidelines at https://marcelomarkus.github.io/b-fast/llms.txt to implement binary endpoints.

About B-FAST

Key Achievements:

  • 🚀 4.1x faster than orjson for simple objects (2.01 ms)
  • 🚀 5.7x faster than orjson on 100 Mbps networks (round-trip)
  • 🌊 12,500+ frames/sec sustained streaming throughput (~139 µs latency)
  • 📦 89% smaller payloads with built-in LZ4 compression
  • ⚡ 14-96x speedup for NumPy arrays
  • 🎯 Competitive even on ultra-fast 10 Gbps networks

B-FAST Performance Benchmarks

B-FAST performance comparison across 6 key scenarios: simple objects encoding, zero-copy NumPy arrays, payload size, 100 Mbps round-trip, streaming decode time, and streaming throughput. B-FAST demonstrates clear superiority in speed (2.1-14x faster) and bandwidth efficiency (90% reduction with LZ4).

Developed by: marcelomarkus

📄 License

Distributed under the MIT License. See LICENSE for more information.

Metadata

Release files for bfast-py 1.9.0

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 bfast-py 1.9.0
File Interpreter ABI Platform Actions
bfast_py-1.9.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details for bfast_py-1.9.0-cp310-abi3-win_amd64.whl
bfast_py-1.9.0-cp310-abi3-manylinux_2_34_x86_64.whl CPython 3.10 abi3 Linux glibc 2.34+ x86-64 Details for bfast_py-1.9.0-cp310-abi3-manylinux_2_34_x86_64.whl
bfast_py-1.9.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details for bfast_py-1.9.0-cp310-abi3-macosx_11_0_arm64.whl

Total release size: 1.1 MB

Release files / bfast_py-1.9.0-cp310-abi3-win_amd64.whl

Download URL bfast_py-1.9.0-cp310-abi3-win_amd64.whl
Size 299.4 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
b5de35091c42eee140d050a86049b83a2766d50c75c9cffd8909a67956ef5b1a
BLAKE2b-256 checksum
How to use checksums
49ccb476468f9fcbffd3020bd0e942f46c6a94aab3048f9f9e0f4f724735658c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / bfast_py-1.9.0-cp310-abi3-manylinux_2_34_x86_64.whl

Download URL bfast_py-1.9.0-cp310-abi3-manylinux_2_34_x86_64.whl
Size 423.7 kB
Tags CPython 3.10 Linux glibc 2.34+ x86-64 abi3
SHA-256 checksum
How to use checksums
4365675e29a4feff02ce749e536256fb0c883b09039a94e52ab07fa5eb952c97
BLAKE2b-256 checksum
How to use checksums
453bcb621136147cac18d740205f2017a7de2d4e5360dc80ee1291c3137552ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / bfast_py-1.9.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL bfast_py-1.9.0-cp310-abi3-macosx_11_0_arm64.whl
Size 387.2 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
25846d4840e3250b4c4ddabf904d8ab54fc275d05133702c17ce5e3bae36e88e
BLAKE2b-256 checksum
How to use checksums
778041a6d0f424a79c669f18e0f5196c5413dee81703eaa67629aafb8edea492
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for bfast-py 1.9.0

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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