Skip to main content

FlexBox layout engine for Python

Project description

FlexBox layout with Yoga in Python

FlexBox is a very neat layout engine available in all browsers. You can play around with it in this Playground to see which properties you need to get the desired results.

This is how to use it in Python with this project:

from flexbox import box, compute_layout

layout = compute_layout(
    box(width=610, flex_direction="row")(
        box(id="cal", flex_grow=1, flex_wrap="wrap", padding=5, justify_content="stretch")(
            box(width=90, height=90, margin=5, flex_grow=1)
            for _ in range(31)
        ),
        box(
            id="legend",
            position="absolute",
            width=200,
            height=200,
            right=25,
            top=25,
        ),
    )
)

# Access the computed layout

(layout / "legend").height
[box.width for box in layout.glob("/calender/*")]
layout["/legend"].x(0.5)  # horizontal center of the legend box


# Make a simple drawing of all boxes in the layout
from domtree.svg import svg, g, rect, text

print(
    svg(width=layout.width, height=layout.height)(
        g(name=name)(
            rect(
                fill="rgba(0,0,0,0.1)",
                stroke="rgba(0,0,0,0.4)",
                stroke_width=".3",
                x=box.left,
                y=box.top,
                height=box.height,
                width=box.width,
            ),
            text(
                x=box.x(0.5),
                y=box.y(0.5),
                text_anchor="middle",
                font_size=10,
                alignment_baseline="middle",
            )(name),
        )
        for name, box in layout.items()
    )
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flexbox-0.0.2.tar.gz (64.8 kB view hashes)

Uploaded Source

Built Distributions

flexbox-0.0.2-pp39-pypy39_pp73-win_amd64.whl (274.4 kB view hashes)

Uploaded PyPy Windows x86-64

flexbox-0.0.2-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (416.3 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

flexbox-0.0.2-pp39-pypy39_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (446.8 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686

flexbox-0.0.2-pp39-pypy39_pp73-macosx_10_9_x86_64.whl (329.0 kB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

flexbox-0.0.2-pp38-pypy38_pp73-win_amd64.whl (274.6 kB view hashes)

Uploaded PyPy Windows x86-64

flexbox-0.0.2-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (416.8 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

flexbox-0.0.2-pp38-pypy38_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (447.1 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686

flexbox-0.0.2-pp38-pypy38_pp73-macosx_10_9_x86_64.whl (329.6 kB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

flexbox-0.0.2-pp37-pypy37_pp73-win_amd64.whl (273.4 kB view hashes)

Uploaded PyPy Windows x86-64

flexbox-0.0.2-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (418.0 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

flexbox-0.0.2-pp37-pypy37_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (448.7 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686

flexbox-0.0.2-pp37-pypy37_pp73-macosx_10_9_x86_64.whl (327.0 kB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

flexbox-0.0.2-cp311-cp311-win_amd64.whl (140.9 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

flexbox-0.0.2-cp311-cp311-win32.whl (118.7 kB view hashes)

Uploaded CPython 3.11 Windows x86

flexbox-0.0.2-cp311-cp311-musllinux_1_1_x86_64.whl (727.8 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

flexbox-0.0.2-cp311-cp311-musllinux_1_1_i686.whl (795.7 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

flexbox-0.0.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (211.9 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

flexbox-0.0.2-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl (227.2 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ i686

flexbox-0.0.2-cp311-cp311-macosx_10_9_x86_64.whl (170.4 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

flexbox-0.0.2-cp311-cp311-macosx_10_9_universal2.whl (319.0 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64)

flexbox-0.0.2-cp310-cp310-win_amd64.whl (140.9 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

flexbox-0.0.2-cp310-cp310-win32.whl (118.6 kB view hashes)

Uploaded CPython 3.10 Windows x86

flexbox-0.0.2-cp310-cp310-musllinux_1_1_x86_64.whl (727.8 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

flexbox-0.0.2-cp310-cp310-musllinux_1_1_i686.whl (795.7 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

flexbox-0.0.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (212.0 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

flexbox-0.0.2-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl (227.2 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686

flexbox-0.0.2-cp310-cp310-macosx_10_9_x86_64.whl (170.4 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

flexbox-0.0.2-cp310-cp310-macosx_10_9_universal2.whl (319.1 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64)

flexbox-0.0.2-cp39-cp39-win_amd64.whl (140.9 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

flexbox-0.0.2-cp39-cp39-win32.whl (118.7 kB view hashes)

Uploaded CPython 3.9 Windows x86

flexbox-0.0.2-cp39-cp39-musllinux_1_1_x86_64.whl (727.8 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

flexbox-0.0.2-cp39-cp39-musllinux_1_1_i686.whl (796.3 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

flexbox-0.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (212.2 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

flexbox-0.0.2-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl (227.5 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686

flexbox-0.0.2-cp39-cp39-macosx_10_9_x86_64.whl (170.5 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

flexbox-0.0.2-cp39-cp39-macosx_10_9_universal2.whl (319.2 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64)

flexbox-0.0.2-cp38-cp38-win_amd64.whl (140.9 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

flexbox-0.0.2-cp38-cp38-win32.whl (118.7 kB view hashes)

Uploaded CPython 3.8 Windows x86

flexbox-0.0.2-cp38-cp38-musllinux_1_1_x86_64.whl (727.5 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

flexbox-0.0.2-cp38-cp38-musllinux_1_1_i686.whl (795.7 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ i686

flexbox-0.0.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (212.0 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

flexbox-0.0.2-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl (227.2 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ i686

flexbox-0.0.2-cp38-cp38-macosx_10_9_x86_64.whl (170.4 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

flexbox-0.0.2-cp38-cp38-macosx_10_9_universal2.whl (319.0 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ universal2 (ARM64, x86-64)

flexbox-0.0.2-cp37-cp37m-win_amd64.whl (139.8 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

flexbox-0.0.2-cp37-cp37m-win32.whl (120.4 kB view hashes)

Uploaded CPython 3.7m Windows x86

flexbox-0.0.2-cp37-cp37m-musllinux_1_1_x86_64.whl (729.9 kB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ x86-64

flexbox-0.0.2-cp37-cp37m-musllinux_1_1_i686.whl (798.6 kB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ i686

flexbox-0.0.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (213.9 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

flexbox-0.0.2-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl (229.4 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ i686

flexbox-0.0.2-cp37-cp37m-macosx_10_9_x86_64.whl (168.6 kB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page