diff --git a/CHANGELOG.md b/CHANGELOG.md index 33309dc..ea5dafc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,21 @@ All notable changes to this project will be documented in this file. +## [1.2.1] - 2026-04-24 + +### 🚀 Features +- **Built-in FastAPI Response**: Added `BFastResponse` directly to the `b_fast` package for easier integration. +- **Improved Type Support**: Better handling of `BFastError` and updated `BFastResponse` to use built-in encoder. + +### 🔧 Fixes +- **Module Visibility**: Fixed `ModuleNotFoundError`/`ImportError` when using the library in external projects by correctly exporting `BFast` in `__init__.py`. +- **Typings Organization**: Moved and renamed `.pyi` file to `python/b_fast/_b_fast.pyi` to ensure correct recognition by IDEs and type checkers after installation. +- **FastAPI Dependency**: Updated `README` to recommend installation with `[fastapi]` extra for projects using FastAPI. + +### 📚 Documentation +- Updated `README` with simplified FastAPI usage example. +- Fixed installation instructions for better clarity. + ## [1.1.0] - 2026-02-07 ### 🚀 Features diff --git a/Cargo.toml b/Cargo.toml index d8a3f05..ca390e2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "b_fast" -version = "1.2.0" +version = "1.2.1" edition = "2021" [lib] diff --git a/README.md b/README.md index ae2fee6..245b43d 100644 --- a/README.md +++ b/README.md @@ -64,11 +64,17 @@ Complete test including network transfer and deserialization (10,000 objects): ### Backend (Python) ```bash -uv add bfast-py +# Basic installation +pip install bfast-py + +# With FastAPI support +pip install "bfast-py[fastapi]" ``` -or +or with `uv`: ```bash -pip install bfast-py +uv add bfast-py +# or +uv add "bfast-py[fastapi]" ``` ### Frontend (TypeScript) @@ -81,22 +87,12 @@ npm install bfast-client ### Backend (Python) #### 1. FastAPI (Direct Integration) ⭐ Recommended -B-FAST integrates seamlessly as a response class. +B-FAST includes a built-in `BFastResponse` for seamless integration. ```python -from fastapi import FastAPI, Response +from fastapi import FastAPI from pydantic import BaseModel -import b_fast - -class BFastResponse(Response): - media_type = "application/x-bfast" - - def __init__(self, content=None, *args, **kwargs): - super().__init__(content, *args, **kwargs) - self.encoder = b_fast.BFast() - - def render(self, content) -> bytes: - return self.encoder.encode_packed(content, compress=True) +from b_fast import BFastResponse app = FastAPI() @@ -106,6 +102,7 @@ class User(BaseModel): @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)] ``` diff --git a/client-ts/package-lock.json b/client-ts/package-lock.json index 5056f37..7c219ac 100644 --- a/client-ts/package-lock.json +++ b/client-ts/package-lock.json @@ -1,17 +1,32 @@ { - "name": "@b-fast/client", - "version": "1.0.0", + "name": "bfast-client", + "version": "1.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "@b-fast/client", - "version": "1.0.0", + "name": "bfast-client", + "version": "1.1.0", + "license": "MIT", "dependencies": { "lz4js": "^0.2.0" }, "devDependencies": { + "@types/node": "^25.6.0", "typescript": "^5.0.0" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@types/node": { + "version": "25.6.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-25.6.0.tgz", + "integrity": "sha512-+qIYRKdNYJwY3vRCZMdJbPLJAtGjQBudzZzdzwQYkEPQd+PJGixUL5QfvCLDaULoLv+RhT3LDkwEfKaAkgSmNQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~7.19.0" } }, "node_modules/lz4js": { @@ -33,6 +48,13 @@ "engines": { "node": ">=14.17" } + }, + "node_modules/undici-types": { + "version": "7.19.2", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.19.2.tgz", + "integrity": "sha512-qYVnV5OEm2AW8cJMCpdV20CDyaN3g0AjDlOGf1OW4iaDEx8MwdtChUp4zu4H0VP3nDRF/8RKWH+IPp9uW0YGZg==", + "dev": true, + "license": "MIT" } } } diff --git a/client-ts/package.json b/client-ts/package.json index 908b3a4..7f52ab4 100644 --- a/client-ts/package.json +++ b/client-ts/package.json @@ -32,9 +32,10 @@ "lz4js": "^0.2.0" }, "devDependencies": { + "@types/node": "^25.6.0", "typescript": "^5.0.0" }, "engines": { "node": ">=14.0.0" } -} \ No newline at end of file +} diff --git a/pyproject.toml b/pyproject.toml index 534b367..a9262ab 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "maturin" [project] name = "bfast-py" -version = "1.2.0" +version = "1.2.1" description = "⚡ B-FAST (Binary Fast Adaptive Serialization Transfer) - Protocolo de serialização binária de ultra-alta performance, desenvolvido em Rust para o ecossistema Python e TypeScript" readme = "README.md" requires-python = ">=3.8" diff --git a/python/b_fast/__init__.py b/python/b_fast/__init__.py index a61c2bc..f368754 100644 --- a/python/b_fast/__init__.py +++ b/python/b_fast/__init__.py @@ -4,8 +4,8 @@ Ultra-fast binary serialization library with Rust backend. """ -from ._b_fast import BFast +from ._b_fast import BFast, BFastError from .integration import BFastResponse -__version__ = "1.2.0" -__all__ = ["BFast", "BFastResponse"] +__version__ = "1.2.1" +__all__ = ["BFast", "BFastError", "BFastResponse"] diff --git a/python/b_fast.pyi b/python/b_fast/_b_fast.pyi similarity index 100% rename from python/b_fast.pyi rename to python/b_fast/_b_fast.pyi diff --git a/python/b_fast/integration.py b/python/b_fast/integration.py index 946fe24..4093298 100644 --- a/python/b_fast/integration.py +++ b/python/b_fast/integration.py @@ -19,14 +19,14 @@ class BFastResponse(Response): def __init__(self, content: Any, **kwargs): if not FASTAPI_AVAILABLE: raise ImportError( - "FastAPI is required to use BFastResponse. Install it with 'pip install fastapi'." + "FastAPI is required to use BFastResponse. Install it with 'pip install bfast-py[fastapi]'." ) # Delayed import to avoid circular dependency from ._b_fast import BFast - super().__init__(content=content, **kwargs) self.encoder = BFast() + super().__init__(content=content, **kwargs) def render(self, content: Any) -> bytes: return self.encoder.encode_packed(content, compress=True)