yoga-python
Python bindings for Facebook's Yoga layout engine — a cross-platform implementation of CSS Flexbox.
Yoga computes a layout tree of nodes with flexbox styles and outputs pixel-perfect positions. This package wraps the full C++ engine via nanobind, giving you the same layout behavior you get in React Native, Litho, and other Yoga-backed frameworks — directly from Python.
Installation
pip install yoga-python
Building from source requires a C++20 compiler, CMake 3.15+, and nanobind:
pip install scikit-build-core nanobind
pip install .
Quick start
from yoga import (
Node, Config, Direction, FlexDirection, Justify,
Align, Edge, YGValuePoint, YGValuePercent,
)
root = Node()
root.flex_direction = FlexDirection.Row
root.width = YGValuePoint(300)
root.height = YGValuePoint(200)
root.set_padding(Edge.All, 10)
child_a = Node()
child_a.flex_grow = 1
child_a.set_margin(Edge.Right, 10)
root.insert_child(child_a, 0)
child_b = Node()
child_b.flex_grow = 2
root.insert_child(child_b, 1)
root.calculate_layout(300, 200, Direction.LTR)
print(f"child_a: {child_a.layout_left}, {child_a.layout_top}, "
f"{child_a.layout_width}x{child_a.layout_height}")
# child_a: 10.0, 10.0, 90.0x180.0
print(f"child_b: {child_b.layout_left}, {child_b.layout_top}, "
f"{child_b.layout_width}x{child_b.layout_height}")
# child_b: 110.0, 10.0, 180.0x180.0
API overview
Node
The primary object. Create nodes, configure their styles, build a tree, then call calculate_layout.
node = Node() # default config
node = Node(config) # with explicit config
Style properties (set directly as attributes):
| Property | Type | Example |
|---|---|---|
flex_direction |
FlexDirection |
node.flex_direction = FlexDirection.Row |
justify_content |
Justify |
node.justify_content = Justify.Center |
align_items |
Align |
node.align_items = Align.Stretch |
align_self |
Align |
node.align_self = Align.FlexEnd |
align_content |
Align |
node.align_content = Align.SpaceBetween |
flex_wrap |
Wrap |
node.flex_wrap = Wrap.Wrap |
overflow |
Overflow |
node.overflow = Overflow.Hidden |
display |
Display |
node.display = Display.Flex |
position_type |
PositionType |
node.position_type = PositionType.Absolute |
flex_grow |
float |
node.flex_grow = 1.0 |
flex_shrink |
float |
node.flex_shrink = 0.0 |
flex_basis |
YGValue |
node.flex_basis = YGValuePoint(100) |
width / height |
YGValue |
node.width = YGValuePercent(50) |
min_width / max_width |
YGValue |
node.min_width = YGValuePoint(80) |
min_height / max_height |
YGValue |
node.max_height = YGValuePoint(400) |
aspect_ratio |
float |
node.aspect_ratio = 16 / 9 |
box_sizing |
BoxSizing |
node.box_sizing = BoxSizing.ContentBox |
direction |
Direction |
node.direction = Direction.LTR |
Edge-based properties (margin, padding, border, position):
node.set_margin(Edge.Left, 10) # points
node.set_margin(Edge.Top, YGValuePercent(5)) # percent
node.set_padding(Edge.All, 20)
node.set_border(Edge.Bottom, 1)
node.set_position(Edge.Left, YGValuePoint(50))
Tree manipulation:
node.insert_child(child, index)
node.remove_child(child)
node.remove_all_children()
node.set_children([child_a, child_b])
node.child_count # int
node[index] # Node (supports indexing)
Layout:
node.calculate_layout(width, height, Direction.LTR)
node.layout_left # float
node.layout_top # float
node.layout_width # float
node.layout_height # float
node.layout_direction # Direction
node.layout_margin(Edge.Left) # float
node.layout_padding(Edge.Top) # float
node.layout_border(Edge.Right) # float
Measure functions for leaf nodes with custom content sizing:
def measure(node, width, width_mode, height, height_mode):
return {"width": 100, "height": 50}
node.set_measure_func(measure)
Baseline functions for custom baseline alignment:
def baseline(node, width, height):
return height * 0.8
node.set_baseline_func(baseline)
Config
config = Config()
config.use_web_defaults = True
config.point_scale_factor = 2.0
config.errata = Errata.StretchFlexBasis
Values
YGValuePoint(100) # 100px
YGValuePercent(50) # 50%
YGValueAuto # auto
YGValueUndefined # undefined
Enums
All Yoga enums are available as Python enum types (nanobind enums, int-convertible):
Direction, FlexDirection, Justify, Align, PositionType, Wrap, Overflow, Display, Edge, Unit, MeasureMode, Dimension, BoxSizing, Gutter, Errata, NodeType, LogLevel, ExperimentalFeature
Development
git clone https://github.com/banditburai/yoga-python.git
cd yoga-python
uv sync --dev
# Run tests
uv run pytest tests/ -v
# Lint & type checking
uv run ruff check
uv run ruff format --check
uv run pyright
Test coverage
The test suite is a 1:1 port of the Yoga C++ test suite — 822 tests covering all layout modes, edge cases, and behaviors. Tests that the C++ suite itself skips (GTEST_SKIP) are also skipped in Python.
License
MIT — same as Yoga.
Metadata
Release files for yoga-python 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| yoga_python-0.1.5.tar.gz | 106.1 kB | Details |
Built distributions (wheels)
Total release size: 1.8 MB
Release files / yoga_python-0.1.5.tar.gz
| Download URL | yoga_python-0.1.5.tar.gz |
|---|---|
| Size | 106.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e4d46061d7d50edfc249370b2b006f3bd926e4ed09f8fb8d453b54c4690eaa7f
|
|
BLAKE2b-256 checksum How to use checksums |
816d4504e0d97154b25b67a422d6c299e4b05f4b9669bdb2831b8f8caee30dc5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 26, 2026.
Transparency logRelease files / yoga_python-0.1.5-cp313-cp313-win_amd64.whl
| Download URL | yoga_python-0.1.5-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 168.7 kB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
0e6fbccf622a3e81b15cd306ef9838ffbcd5f7109a0875f277a54ada64abf792
|
|
BLAKE2b-256 checksum How to use checksums |
be995d9dc4fb16d542acfe2777300db63f53021420e209a24ee65c1cf7430286
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 26, 2026.
Transparency logRelease files / yoga_python-0.1.5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | yoga_python-0.1.5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 201.5 kB |
| Tags | CPython 3.13 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
de680c7e60f43549193b23d6e9d9f9db18425ebfd9786b06534e32b4b1f719dc
|
|
BLAKE2b-256 checksum How to use checksums |
8dd0cdd84b2e05eafa9e9a705ba3075b3ecdfe87db844ca7d2c6a4b7e3cde221
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 26, 2026.
Transparency logRelease files / yoga_python-0.1.5-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
| Download URL | yoga_python-0.1.5-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl |
|---|---|
| Size | 181.7 kB |
| Tags | CPython 3.13 Linux glibc 2.27+ ARM64 Linux glibc 2.28+ ARM64 |
|
SHA-256 checksum How to use checksums |
e0186adce95781a068b42ad7514273865db56cf5b55481b055b3334fd4e6c722
|
|
BLAKE2b-256 checksum How to use checksums |
40aa6cf1cb78f36a04303d959fdcb04f1ab83568f66e0f5626a98433f45b34d5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 26, 2026.
Transparency logRelease files / yoga_python-0.1.5-cp313-cp313-macosx_11_0_arm64.whl
| Download URL | yoga_python-0.1.5-cp313-cp313-macosx_11_0_arm64.whl |
|---|---|
| Size | 143.4 kB |
| Tags | CPython 3.13 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
5300efadb191a964bea53fff98bf278a1c2ee8132cc38445ffaf02a4c194f87a
|
|
BLAKE2b-256 checksum How to use checksums |
3b3a4d743e1f3244a66951755604c563b35683e67f7f68a1d73697b795a956c1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 26, 2026.
Transparency logRelease files / yoga_python-0.1.5-cp313-cp313-macosx_10_13_x86_64.whl
| Download URL | yoga_python-0.1.5-cp313-cp313-macosx_10_13_x86_64.whl |
|---|---|
| Size | 159.0 kB |
| Tags | CPython 3.13 macOS 10.13+ x86-64 |
|
SHA-256 checksum How to use checksums |
258d75cee54f5110ff48764b5f50f8f309afd79c5fa12121051d8eba0ca80b6a
|
|
BLAKE2b-256 checksum How to use checksums |
5bfb25abd12fadaa8b63abaa91e56f27a596c28e746e0a7f23f3ffaa20e93d3b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 26, 2026.
Transparency logRelease files / yoga_python-0.1.5-cp312-cp312-win_amd64.whl
| Download URL | yoga_python-0.1.5-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 168.8 kB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
e51297db6122239e883dddfd97180eea9c6338cf523b1ba648b1aee64fd7e941
|
|
BLAKE2b-256 checksum How to use checksums |
c261f79aa36b92f35cd96d83032d12b1ac9a001a79f9c53b0d6b4b6723ace063
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 26, 2026.
Transparency logRelease files / yoga_python-0.1.5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | yoga_python-0.1.5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 201.5 kB |
| Tags | CPython 3.12 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
aa25b1b0b30aa7148d4f64ada9b11bf2c1deb62a490ecf6904d224a1b5fa452c
|
|
BLAKE2b-256 checksum How to use checksums |
0f2a0ddd81bc5894a166a09a3dd528ff8f17219abe1e6d9c5e6c3ae98f7a2878
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 26, 2026.
Transparency logRelease files / yoga_python-0.1.5-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
| Download URL | yoga_python-0.1.5-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl |
|---|---|
| Size | 181.7 kB |
| Tags | CPython 3.12 Linux glibc 2.27+ ARM64 Linux glibc 2.28+ ARM64 |
|
SHA-256 checksum How to use checksums |
f01d3bc587ffceb80899be79e5fec7abae20124e065c4fa9cbad718d5c40a3e3
|
|
BLAKE2b-256 checksum How to use checksums |
8a9529e2907b35f324a6bd7fd8ee44e715f882e58dff0baf714538ac1d339ecb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 26, 2026.
Transparency logRelease files / yoga_python-0.1.5-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | yoga_python-0.1.5-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 143.4 kB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
b5f486449c98aa314add830df0820b640dd6c6444ea407edad7cd5238f0ad32c
|
|
BLAKE2b-256 checksum How to use checksums |
0ba42b3da75f2277d814db6e45cfea9d437a040960a4c07533ced6fbc31e41b7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 26, 2026.
Transparency logRelease files / yoga_python-0.1.5-cp312-cp312-macosx_10_13_x86_64.whl
| Download URL | yoga_python-0.1.5-cp312-cp312-macosx_10_13_x86_64.whl |
|---|---|
| Size | 159.1 kB |
| Tags | CPython 3.12 macOS 10.13+ x86-64 |
|
SHA-256 checksum How to use checksums |
7de261538ff693ddbd8f884e699ab3c783813e6bf2765d28cf75fd00e75c4484
|
|
BLAKE2b-256 checksum How to use checksums |
991210ff8359dbdf415328d566f075726abf877fc72358ff5e4643eead3ae55f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 26, 2026.
Transparency log