Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8c7d5c3
feat(python): add bfloat16 and bfloat16_array support
asadjan4611 Feb 12, 2026
c89d86e
style(python): fix code formatting for bfloat16 implementation
asadjan4611 Feb 12, 2026
b2bb7c6
fix(python): remove trailing newline in bfloat16_array.py to match co…
asadjan4611 Feb 12, 2026
6537f74
fix(python): resolve Cython compilation errors for bfloat16
asadjan4611 Feb 12, 2026
b6793a5
fix(python): use memcpy for safe type punning in bfloat16 conversion
asadjan4611 Feb 13, 2026
e387339
fix(python): use explicit size constant for ARM compatibility
asadjan4611 Feb 13, 2026
71241ba
fix(python): correct row schema Arrow conversion type ids
asadjan4611 Feb 13, 2026
8066ace
fix(python): build and export bfloat16 python module
asadjan4611 Feb 13, 2026
8ed6f57
docs(python): document bfloat16 support and stabilize pure mode seria…
asadjan4611 Feb 13, 2026
9fcb74d
fix(python): configure bazel shell for windows editable builds
asadjan4611 Feb 13, 2026
8866639
Merge branch 'main' into feat/python-bfloat16-support
asadjan4611 Feb 20, 2026
102acfb
fix(python): restore xlang serializer base after conflict merge
asadjan4611 Feb 20, 2026
bedb82e
fix(python): restore xlang serializer base in cython runtime
asadjan4611 Feb 21, 2026
2f2b6b4
fix(python): align bfloat16 serializers with unified API and typed bu…
asadjan4611 Feb 21, 2026
c9e2e12
fix(python): resolve bfloat16 cython build and serializer API drift
asadjan4611 Feb 21, 2026
56f45d3
style(python): align bfloat16 files with ci formatter
asadjan4611 Feb 21, 2026
efb0100
fix(python): include bfloat16 pxd in format cython target
asadjan4611 Feb 21, 2026
f1a3f42
fix(python): resolve bfloat16 cython redeclaration and static method …
asadjan4611 Feb 21, 2026
9d74ae2
fix(python): remove obsolete xlang arg for dataclass serializers
asadjan4611 Feb 21, 2026
ec59341
fix(python): accept legacy xlang kwarg in dataclass serializers
asadjan4611 Feb 21, 2026
848a1cd
fix(python): repair unsigned xlang dataclass refs and retry bazel fetch
asadjan4611 Feb 21, 2026
66dbf19
style(python): format setup retry log line
asadjan4611 Feb 21, 2026
3ac6ba8
fix(python): remove keyword arguments from cpdef function calls in co…
asadjan4611 Feb 21, 2026
308bde9
fix(python): remove keyword arguments from cpdef function calls in st…
asadjan4611 Feb 21, 2026
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
18 changes: 18 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pyx_library(
name = "buffer",
srcs = glob([
"python/pyfory/includes/*.pxd",
"python/pyfory/bfloat16.pxd",
"python/pyfory/buffer.pxd",
"python/pyfory/buffer.pyx",
"python/pyfory/__init__.py",
Expand Down Expand Up @@ -54,6 +55,7 @@ pyx_library(
name = "serialization",
srcs = glob([
"python/pyfory/includes/*.pxd",
"python/pyfory/bfloat16.pxd",
"python/pyfory/buffer.pxd",
"python/pyfory/serialization.pyx",
"python/pyfory/*.pxi",
Expand All @@ -70,12 +72,25 @@ pyx_library(
],
)

pyx_library(
name = "bfloat16",
srcs = glob([
"python/pyfory/bfloat16.pxd",
"python/pyfory/bfloat16.pyx",
"python/pyfory/__init__.py",
]),
cc_kwargs = dict(
linkstatic = 1,
),
)

pyx_library(
name = "_format",
srcs = glob(
[
"python/pyfory/__init__.py",
"python/pyfory/includes/*.pxd",
"python/pyfory/bfloat16.pxd",
"python/pyfory/buffer.pxd",
"python/pyfory/*.pxi",
"python/pyfory/format/_format.pyx",
Expand All @@ -96,6 +111,7 @@ genrule(
name = "cp_fory_so",
srcs = [
":python/pyfory/buffer.so",
":python/pyfory/bfloat16.so",
":python/pyfory/lib/mmh3/mmh3.so",
":python/pyfory/format/_format.so",
":python/pyfory/serialization.so",
Expand All @@ -111,11 +127,13 @@ genrule(
if [ "$${u_name: 0: 4}" == "MING" ] || [ "$${u_name: 0: 4}" == "MSYS" ]
then
cp -f $(location python/pyfory/buffer.so) "$$WORK_DIR/python/pyfory/buffer.pyd"
cp -f $(location python/pyfory/bfloat16.so) "$$WORK_DIR/python/pyfory/bfloat16.pyd"
cp -f $(location python/pyfory/lib/mmh3/mmh3.so) "$$WORK_DIR/python/pyfory/lib/mmh3/mmh3.pyd"
cp -f $(location python/pyfory/format/_format.so) "$$WORK_DIR/python/pyfory/format/_format.pyd"
cp -f $(location python/pyfory/serialization.so) "$$WORK_DIR/python/pyfory/serialization.pyd"
else
cp -f $(location python/pyfory/buffer.so) "$$WORK_DIR/python/pyfory"
cp -f $(location python/pyfory/bfloat16.so) "$$WORK_DIR/python/pyfory"
cp -f $(location python/pyfory/lib/mmh3/mmh3.so) "$$WORK_DIR/python/pyfory/lib/mmh3"
cp -f $(location python/pyfory/format/_format.so) "$$WORK_DIR/python/pyfory/format"
cp -f $(location python/pyfory/serialization.so) "$$WORK_DIR/python/pyfory"
Expand Down
28 changes: 28 additions & 0 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,34 @@ fory.register(Person.class, "example.Person");
Person person = (Person) fory.deserialize(binaryData);
```

### BFloat16 Support

`pyfory` supports `bfloat16` scalar values and `bfloat16` arrays in xlang mode:

- Scalar type: `pyfory.BFloat16` (type id `18`)
- Array type: `pyfory.BFloat16Array` (type id `54`)

```python
import pyfory
from pyfory import BFloat16, BFloat16Array

fory = pyfory.Fory(xlang=True, ref=False, strict=True)

# Scalar bfloat16
v = BFloat16(3.1415926)
data = fory.serialize(v)
out = fory.deserialize(data)
print(float(out))

# bfloat16 array
arr = BFloat16Array([1.0, 2.5, -3.25])
data = fory.serialize(arr)
out = fory.deserialize(data)
print(out)
```

`BFloat16Array` stores values in a packed `array('H')` representation and writes bytes in little-endian order for cross-language compatibility.

## 📊 Row Format - Zero-Copy Processing

Apache Fury™ provides a random-access row format that enables reading nested fields from binary data without full deserialization. This drastically reduces overhead when working with large objects where only partial data access is needed. The format also supports memory-mapped files for ultra-low memory footprint.
Expand Down
15 changes: 15 additions & 0 deletions python/pyfory/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
TaggedUint64Serializer,
Float32Serializer,
Float64Serializer,
BFloat16Serializer,
StringSerializer,
DateSerializer,
TimestampSerializer,
Expand Down Expand Up @@ -88,6 +89,8 @@
tagged_uint64,
float32,
float64,
bfloat16 as bfloat16_type,
bfloat16_array,
int8_array,
uint8_array,
int16_array,
Expand Down Expand Up @@ -118,6 +121,13 @@
from pyfory.policy import DeserializationPolicy # noqa: F401 # pylint: disable=unused-import
from pyfory.buffer import Buffer # noqa: F401 # pylint: disable=unused-import

# BFloat16 support
from pyfory.bfloat16 import bfloat16 # noqa: F401
from pyfory.bfloat16_array import BFloat16Array # noqa: F401

# Keep compatibility with existing API naming.
BFloat16 = bfloat16

__version__ = "0.16.0.dev0"

__all__ = [
Expand Down Expand Up @@ -151,6 +161,10 @@
"tagged_uint64",
"float32",
"float64",
"BFloat16",
"BFloat16Array",
"bfloat16",
"bfloat16_array",
"int8_array",
"uint8_array",
"int16_array",
Expand Down Expand Up @@ -192,6 +206,7 @@
"TaggedUint64Serializer",
"Float32Serializer",
"Float64Serializer",
"BFloat16Serializer",
"StringSerializer",
"DateSerializer",
"TimestampSerializer",
Expand Down
Loading
Loading