Layout library for Python (based on Taffy, a rust-powered implementation of CSS Grid/Flexbox)
Project description
stretchable
stretchable is a layout library for Python that enables context-agnostic layout operations using CSS Grid and Flexbox. Possible uses include UI layouts, page layouts for reports, complex plotting layouts, etc.
It implements Python bindings for Taffy, an implementation of Grid/Flexbox written in Rust. It was originally based on Stretch (hence the name), but has since migrated to use Taffy. It is multi-platform and there are distributions available for Windows, Linux and macOS.
Getting Started
stretchable is a Python package hosted on PyPI. It can be installed using pip:
python -m pip install stretchable
Building a tree of nodes and calculating the layout is as simple as:
from stretchable import Edge, Node
from stretchable.style import AUTO, PCT
# Build node tree
root = Node(
margin=20,
size=(500, 300),
).add(
Node(border=5, size=(50 * PCT, AUTO)),
Node(key="child", padding=10 * PCT, size=50 * PCT),
)
# Compute layout
root.compute_layout()
# Get the second child node
child_node = root.find("/child")
content_box = child_node.get_box(Edge.CONTENT)
print(content_box)
# Box(x=300.0, y=50.0, width=150.0, height=50.0)
For more information and details, see the documentation.
Contributing
Contributions are welcomed. Please open an issue to clarify/plan implementation details prior to starting the work.
Building
Install Rust with rustup and use maturin develop
for development and maturin build [--release]
to build.
Documentation
To build documentation use make html
(in docs/
folder) or, to use live reloading: sphinx-autobuild docs/source docs/build/html
NOTE: Sometimes, you may need to run make clean html
(in docs/
folder) to ensure that all changes are included in the built html.
Testing
Install test dependencies and invoke pytest
. Note that there are ~650 tests, the majority of which are run using Selenium with the Chrome WebDriver, and the complete test suite can take ~20 minutes to complete. Use pytest --lf
to only run the last-failed tests.
License
This work is released under the MIT license. A copy of the license is provided in the LICENSE file.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for stretchable-1.0.1-cp38-abi3-win_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48c2ab6ce769e923fe66050985865d1b64bd14abf975de57557f7a7e95e61a72 |
|
MD5 | bfd1b2f81f3d034a8d986f66ff3ead83 |
|
BLAKE2b-256 | 9a382e2f949b7311a110afaa8d366860084b8a1ae2d9f0b381cb843940fc7ca7 |
Hashes for stretchable-1.0.1-cp38-abi3-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4fb68fc4c7a7aa3c335ea244e7127a801ab0716d8972ce6293e7de0fb4ac4d6 |
|
MD5 | af5c9fb8db7e22b1b738679578733bca |
|
BLAKE2b-256 | fdac788c9a06f27e1e26ea10d8e18e993787378f51e52c70e0ba049f7b9a4361 |
Hashes for stretchable-1.0.1-cp38-abi3-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00a7461842c052a66f01b44d8792c7bd4954d62317dcd12b929f42f857e1af8b |
|
MD5 | ebd7dfd3f887d475287653835a1a10d7 |
|
BLAKE2b-256 | 9049502968f3ad77a2dd7e911a972c3c7a3f41fb1c011cfed5ca5a9736c910f5 |
Hashes for stretchable-1.0.1-cp38-abi3-musllinux_1_2_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a31bc5c02c7bb3808e56d1feb8409d6710be26721820622b1e1e9a4be78d92a4 |
|
MD5 | c96c3663d004a58777ff81ea245e3ff9 |
|
BLAKE2b-256 | 760c6ac36cc721728e7eeab95c84dbb2b4b244669bb0a5b94d03501ffbabfaef |
Hashes for stretchable-1.0.1-cp38-abi3-musllinux_1_2_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f51a0235484238c909def68e42b7405191ccd3c46ffd51b36ddde52259fc328c |
|
MD5 | d33bb4db030ffb2564447576c8e7fdb9 |
|
BLAKE2b-256 | 6f65219394cc227d21f972c58e25c5476bb8babb2f55eb93fd8e3c6b449febb7 |
Hashes for stretchable-1.0.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee47c637e8040eb092ae3b94f7c67b7ddf0ea76069e3bba742999371a3c4ed3e |
|
MD5 | eaef5a7bb330f167bcd72f2777757bbe |
|
BLAKE2b-256 | ddc10980db97e0264df3de6223687db5fd0964375d08522b29837f264210423b |
Hashes for stretchable-1.0.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7d0d57b553fdb4c4031426b535451931b3968ee26985fced884eb0423d6a9bc |
|
MD5 | 25361a68ca72656c4c04027d3f214c21 |
|
BLAKE2b-256 | 028d5965349bc2389fab4ba3b92fed94455bf2811f84fff0b9019b97e54a4b29 |
Hashes for stretchable-1.0.1-cp38-abi3-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16a17de71ba0c24a27d288fa01ee9b23001340f92860cfbc8329f2fb9865f8bc |
|
MD5 | 8f0ad2fff01c440a97d8930f99fd72de |
|
BLAKE2b-256 | 9395dc7f95b606df06607325c2604c209912a3382fbf434328d7bcdd7e7385f2 |
Hashes for stretchable-1.0.1-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fec26bdb370aca9bb0e15b90a6ca814a1c699d550c495dc08e5b3c029dc59371 |
|
MD5 | feab510ea306f7f8a21255c4c13a597a |
|
BLAKE2b-256 | 8c76e9cd8c750730078c99f7d546aad3e83653001795f3a7ba42cc38986effbe |