Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,15 @@ jobs:
run: pip install pytest pydantic numpy

- name: Run Python tests
run: pytest tests/ -v --tb=short
run: |
# Clear PYTHONPATH to ensure we test the installed wheel, not the local source
export PYTHONPATH=
pytest tests/ -v --tb=short

- name: Run benchmarks (smoke test)
run: python benchmarks/test_10k.py
run: |
export PYTHONPATH=
python benchmarks/test_10k.py

test-typescript:
name: TypeScript Tests
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ known-first-party = ["b_fast"]

[tool.maturin]
python-source = "python"
module-name = "b_fast.b_fast"
module-name = "b_fast._b_fast"
2 changes: 1 addition & 1 deletion python/b_fast/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Ultra-fast binary serialization library with Rust backend.
"""

from .b_fast import BFast
from ._b_fast import BFast
from .integration import BFastResponse

__version__ = "1.2.0"
Expand Down
Binary file added python/b_fast/_b_fast.abi3.so
Binary file not shown.
Binary file added python/b_fast/b_fast.abi3.so
Binary file not shown.
20 changes: 16 additions & 4 deletions python/b_fast/integration.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
from typing import Any

from fastapi import Response

import b_fast
try:
from fastapi import Response
FASTAPI_AVAILABLE = True
except ImportError:
# Fallback class to prevent crash on import
class Response:
def __init__(self, *args, **kwargs):
pass
FASTAPI_AVAILABLE = False


class BFastResponse(Response):
media_type = "application/x-bfast"

def __init__(self, content: Any, **kwargs):
if not FASTAPI_AVAILABLE:
raise ImportError("FastAPI is required to use BFastResponse. Install it with 'pip install fastapi'.")

# Delayed import to avoid circular dependency
from ._b_fast import BFast

super().__init__(content=content, **kwargs)
self.encoder = b_fast.BFast()
self.encoder = BFast()

def render(self, content: Any) -> bytes:
return self.encoder.encode_packed(content, compress=True)
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const TAG_UUID: u8 = 0xD4;
const TAG_DECIMAL: u8 = 0xD5;

#[allow(non_local_definitions)]
#[repr(align(64))]
#[pyclass]
pub struct BFast {
string_table: AHashMap<String, u32>,
Expand Down Expand Up @@ -796,7 +795,7 @@ impl BFast {
}

#[pymodule]
fn b_fast(_py: Python, m: &PyModule) -> PyResult<()> {
fn _b_fast(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_class::<BFast>()?;
m.add(
"BFastError",
Expand Down
Loading