Skip to main content

Layout library for Python (based on Taffy, a rust-powered implementation of CSS Grid/Flexbox)

Project description

stretchable

PyPI - Version Python Versions License GitHub issues GitHub Workflow Status (with event) Documentation Status Test results Test coverage

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


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

stretchable-1.1.3-cp38-abi3-win_arm64.whl (305.1 kB view details)

Uploaded CPython 3.8+ Windows ARM64

stretchable-1.1.3-cp38-abi3-win_amd64.whl (329.1 kB view details)

Uploaded CPython 3.8+ Windows x86-64

stretchable-1.1.3-cp38-abi3-win32.whl (323.6 kB view details)

Uploaded CPython 3.8+ Windows x86

stretchable-1.1.3-cp38-abi3-musllinux_1_2_x86_64.whl (651.1 kB view details)

Uploaded CPython 3.8+ musllinux: musl 1.2+ x86-64

stretchable-1.1.3-cp38-abi3-musllinux_1_2_aarch64.whl (648.5 kB view details)

Uploaded CPython 3.8+ musllinux: musl 1.2+ ARM64

stretchable-1.1.3-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (494.2 kB view details)

Uploaded CPython 3.8+ manylinux: glibc 2.17+ x86-64

stretchable-1.1.3-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (476.5 kB view details)

Uploaded CPython 3.8+ manylinux: glibc 2.17+ ARM64

stretchable-1.1.3-cp38-abi3-macosx_11_0_arm64.whl (424.4 kB view details)

Uploaded CPython 3.8+ macOS 11.0+ ARM64

stretchable-1.1.3-cp38-abi3-macosx_10_12_x86_64.whl (456.6 kB view details)

Uploaded CPython 3.8+ macOS 10.12+ x86-64

File details

Details for the file stretchable-1.1.3-cp38-abi3-win_arm64.whl.

File metadata

File hashes

Hashes for stretchable-1.1.3-cp38-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 b4929ab84d38bc0399f3c94bd52ac8a56ec07b23b8114e6c1b58686288f9cfa3
MD5 51f70c32ef1825747d40e24593d3fab6
BLAKE2b-256 0d8503965fd5477b80e064b1740b7845062999d57dc760586222eb0ab1aa95fd

See more details on using hashes here.

File details

Details for the file stretchable-1.1.3-cp38-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for stretchable-1.1.3-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 7c89c40ac44ea6c2512f61de08ad46f01c7b2f2420e08d7c44ea0b79ef085630
MD5 e02a77fa4f73028fab240160ad9e1f59
BLAKE2b-256 c0a02a02d374a4ae00558f0f874fc2dd89156c7879b60b8150e0b58f6189ff31

See more details on using hashes here.

File details

Details for the file stretchable-1.1.3-cp38-abi3-win32.whl.

File metadata

  • Download URL: stretchable-1.1.3-cp38-abi3-win32.whl
  • Upload date:
  • Size: 323.6 kB
  • Tags: CPython 3.8+, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for stretchable-1.1.3-cp38-abi3-win32.whl
Algorithm Hash digest
SHA256 75351438a39bb1b8882e0f592e3f5e99ef3c6fd3aab6d28d04d6b567d813a1f0
MD5 e5c9411e46c476633068b47736709fb7
BLAKE2b-256 5046d63c9aaf89a93bafefbb9c08b4e4c685219f5134117ad437f1f06a3f188d

See more details on using hashes here.

File details

Details for the file stretchable-1.1.3-cp38-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for stretchable-1.1.3-cp38-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 f452fb0b430d899948e5c2900eeaf59a24613814e0c47ac0743ea975d9113f48
MD5 6162d973681e975721b115c288d00779
BLAKE2b-256 3afc3e378396359d06b87ef3218bc46508dcc9e3f6dc4c7924b06ef701fb6e31

See more details on using hashes here.

File details

Details for the file stretchable-1.1.3-cp38-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for stretchable-1.1.3-cp38-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 f7eeb2a679c7f95066b84f9096901241a757c9194f4eceff28e4ac4fa28b2a5b
MD5 e704eeb09b9bad4cadb06c4209044d1c
BLAKE2b-256 bcebb849fafc2e7192e35545433e1f875b8c7f4f7b2a2576e83c3ce282c08a2e

See more details on using hashes here.

File details

Details for the file stretchable-1.1.3-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for stretchable-1.1.3-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 033fa08d0341c3f762f4a8ea897cd13ce1f08615b3ec6726d5e2dbb71b892079
MD5 d23940344171248fdbf0c766c06c7a1c
BLAKE2b-256 5438d7bb4b9641ff408870838d3f0d977a5094dba724a1d113ac14eb32567490

See more details on using hashes here.

File details

Details for the file stretchable-1.1.3-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for stretchable-1.1.3-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f19b6a6595aef0796e6d26f95eb750348da1f7f35b6825e0c10ff7259ec115b3
MD5 8286ac643a62553be900c0dbfb248689
BLAKE2b-256 1c0e80d3e212fd878a0929c24fcdca16ea0180e76f0f663917fbc03e0fd8a67c

See more details on using hashes here.

File details

Details for the file stretchable-1.1.3-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for stretchable-1.1.3-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 56accdad33cd4193897d429d8e1dc6aea172e9ed53e391c20c829f0ed3ea6f90
MD5 a9673a2ead7c18eaac0040cc2568c130
BLAKE2b-256 b5d89f60c724f9afb9913c8d400190f2743581222a23f19e869623335ec93f94

See more details on using hashes here.

File details

Details for the file stretchable-1.1.3-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for stretchable-1.1.3-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 5c00e9e9b431ff61ff0944b9effd47ba051fa99b44c4072814f7799017ea4087
MD5 6b03ff9a5ed522d0e314f179e3323694
BLAKE2b-256 653ed3375285ba4e5ed6ef22c0bcb9566b274ab4bb0d99e2b68a56d18fb808da

See more details on using hashes here.

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