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 Block, 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 CSS Block, Flexbox and CSS Grid layout algorithms 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 of the child nodes
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 ~900 tests, the majority of which are run using Selenium with the Chrome WebDriver, and the complete test suite can take ~30 minutes to complete. Use pytest --lf
to only run the last-failed tests.
To run basic tests and ensure compatibility with a specific Python version, use Docker and the provided Dockerfile
: docker build . [--build-arg pyver=3.11]
(defaults to lowest supported Python version, currently 3.8).
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
File details
Details for the file stretchable-1.1.4-cp38-abi3-win_arm64.whl
.
File metadata
- Download URL: stretchable-1.1.4-cp38-abi3-win_arm64.whl
- Upload date:
- Size: 306.4 kB
- Tags: CPython 3.8+, Windows ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06f20f56223fa5f48bd5ead1993d813b7470e7a4d688503c9f81121751aea843 |
|
MD5 | ed86fa0313490f9e99634dff99a88623 |
|
BLAKE2b-256 | 32cd98d12499190052a83f156d948f45335737bfd35dffd3c3b15000a6994228 |
File details
Details for the file stretchable-1.1.4-cp38-abi3-win_amd64.whl
.
File metadata
- Download URL: stretchable-1.1.4-cp38-abi3-win_amd64.whl
- Upload date:
- Size: 330.2 kB
- Tags: CPython 3.8+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6433dbab5d0659def9ceb38012566ef45717e0989d2a5cf3cbe2b9c14b0892a |
|
MD5 | dc0da77db56eadebbbf013cff558920e |
|
BLAKE2b-256 | 718d667ce603f468231dd4465c795fd1b13a15db1f581845f54b8264ef558579 |
File details
Details for the file stretchable-1.1.4-cp38-abi3-win32.whl
.
File metadata
- Download URL: stretchable-1.1.4-cp38-abi3-win32.whl
- Upload date:
- Size: 321.1 kB
- Tags: CPython 3.8+, Windows x86
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc5b95686330ab47df39ab61ab2d5b284e2ef61f4301f4e518cf6b0ccbec181c |
|
MD5 | 50069ba7871a63b2409feed17d865cee |
|
BLAKE2b-256 | 511788cec891b06547acbfbbe656390071cecf2cc5c3bb09e856817a1aeefd12 |
File details
Details for the file stretchable-1.1.4-cp38-abi3-musllinux_1_2_x86_64.whl
.
File metadata
- Download URL: stretchable-1.1.4-cp38-abi3-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 645.4 kB
- Tags: CPython 3.8+, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3466b64acb42137aaf806cce9b7c92dd3c457e5ebd02d045dccaaec6a1b346b6 |
|
MD5 | 95c781d1b2bc0a4a8b5be7f4e0269bde |
|
BLAKE2b-256 | f360dd11d16760c21fed56070aa99f861b215e72f766bc2ad016627b36f5fd61 |
File details
Details for the file stretchable-1.1.4-cp38-abi3-musllinux_1_2_aarch64.whl
.
File metadata
- Download URL: stretchable-1.1.4-cp38-abi3-musllinux_1_2_aarch64.whl
- Upload date:
- Size: 644.0 kB
- Tags: CPython 3.8+, musllinux: musl 1.2+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b384850a5d078cda84447ceebe4483a2ee95e7f19f7d9fa10884aacca7f3897e |
|
MD5 | 72dc9032866e87cb232a9987b0060431 |
|
BLAKE2b-256 | e1c23258d6cccdd1081a5499e639abe873db7ef1637edbb935b52120d68847a7 |
File details
Details for the file stretchable-1.1.4-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: stretchable-1.1.4-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 490.9 kB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ebad101f2165a28bd36596037d04313cdf75fab8f9bf89b5fa6366cd90d8baeb |
|
MD5 | 0a59c27de95c6d37812c5ed2742a3c6b |
|
BLAKE2b-256 | 69e16b5f828f1b11b269689d85d80bf203b367dc566757e7ddb667c366c7f257 |
File details
Details for the file stretchable-1.1.4-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: stretchable-1.1.4-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 464.1 kB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c48696f6c222af7d496e45fd9f065a4e3658824a7b95e1c06183ef945621e98 |
|
MD5 | b65e8cd0b16caa965ef52d270c15d06b |
|
BLAKE2b-256 | 1ecf1ae3908b31038f370617753b66134d13789ee463db8369724de566e20fc2 |
File details
Details for the file stretchable-1.1.4-cp38-abi3-macosx_11_0_arm64.whl
.
File metadata
- Download URL: stretchable-1.1.4-cp38-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 422.8 kB
- Tags: CPython 3.8+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16b33415e7cfc76ba2ae3deab51b259edcbab2f587dea182a25824e09f1412e1 |
|
MD5 | 45b19cdf8d72cb2b89d1ee70e08969ab |
|
BLAKE2b-256 | 08d4212859d9e7112d36368eea9849f6396b0a68d060ea7586902ba3816b31e0 |
File details
Details for the file stretchable-1.1.4-cp38-abi3-macosx_10_12_x86_64.whl
.
File metadata
- Download URL: stretchable-1.1.4-cp38-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 454.5 kB
- Tags: CPython 3.8+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e91375f661d37bfe215d396be63f5fcdae4c32b66f2a76b5ffb51e128263a50e |
|
MD5 | d2ca8609dc460664beb3b7857a221264 |
|
BLAKE2b-256 | 032565cd73156d1a8824c3528ce06eb7105c02e63703e1f47a89bfd656537626 |