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.6-cp38-abi3-win_arm64.whl (306.4 kB view details)

Uploaded CPython 3.8+ Windows ARM64

stretchable-1.1.6-cp38-abi3-win_amd64.whl (330.2 kB view details)

Uploaded CPython 3.8+ Windows x86-64

stretchable-1.1.6-cp38-abi3-win32.whl (321.1 kB view details)

Uploaded CPython 3.8+ Windows x86

stretchable-1.1.6-cp38-abi3-musllinux_1_2_x86_64.whl (645.5 kB view details)

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

stretchable-1.1.6-cp38-abi3-musllinux_1_2_aarch64.whl (643.9 kB view details)

Uploaded CPython 3.8+ musllinux: musl 1.2+ ARM64

stretchable-1.1.6-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (490.9 kB view details)

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

stretchable-1.1.6-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (463.8 kB view details)

Uploaded CPython 3.8+ manylinux: glibc 2.17+ ARM64

stretchable-1.1.6-cp38-abi3-macosx_11_0_arm64.whl (422.8 kB view details)

Uploaded CPython 3.8+ macOS 11.0+ ARM64

stretchable-1.1.6-cp38-abi3-macosx_10_12_x86_64.whl (454.3 kB view details)

Uploaded CPython 3.8+ macOS 10.12+ x86-64

File details

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

File metadata

File hashes

Hashes for stretchable-1.1.6-cp38-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 eb3e78ea89549acbe98966cacbdcd6a01fe83a5806f103b0fae6866ff3e7c345
MD5 b2d541461a8cc9aa69f1a26b64cb0bc4
BLAKE2b-256 6d3ae264b9e02943b222998ba04ed0225ca9be4ddb606dac63b4f436e93911fb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stretchable-1.1.6-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 a933fcd13d96a55cd8c54a05f0affdd3e306a4775a87cf9c72e1e47e9f29ebf2
MD5 11e8ebce8387a3fdfaf5d5aaa74a6681
BLAKE2b-256 7507758120f9f65b0573c03e0ee67a7ae577cfedc362b19602fbd54c21bf4cf0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: stretchable-1.1.6-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

Hashes for stretchable-1.1.6-cp38-abi3-win32.whl
Algorithm Hash digest
SHA256 bbb3b89e9981ba925ef5487e5b7a3efc82dfe2eae15e2fe0760393f4e1c6aa6a
MD5 4fd3193cd71f0c9087832e570d5da996
BLAKE2b-256 67375315d811c6f3d270fb9bcfabb610f4238d8ef09ba5c66315479cb22e8355

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stretchable-1.1.6-cp38-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 534e5c8745849bebfc6990384a46af01b28fa883959986fdc274c3821179131c
MD5 550c0d29290d643324d6b57f72b69314
BLAKE2b-256 9ad560844f8d8b6f109ed1e0b4681070f58072d38f6146aa2f66dff62371c085

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stretchable-1.1.6-cp38-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 529f023057178a37e6078d82f9494890ca9683c39dfb047238ec6958ffc289cc
MD5 f143b59e50ad58ae2e5b67aa6119a931
BLAKE2b-256 42dfd11c52c660f8f39b4a45409c0827fd8ad9b73d74208bce9755cafde4ee36

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stretchable-1.1.6-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a607085573548facaf62e9367fbdd103d4d9761cea965927a02d691476123730
MD5 102d6fb3fd081c39eebea2eb5ed3d231
BLAKE2b-256 81f603dad639b923295ebadc436126fb38edefd7557e06eb6aa3d2b00fd2a2c7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stretchable-1.1.6-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 9a3dc96ced7aa17dd0a3e21f0d7535db3928b6ca0f8888062bf8b1a8a933208a
MD5 23c5528ea5c57306573ee837b35ac13f
BLAKE2b-256 9456bdd6163c90b0ca9352f8e559ecb6129cbc4f86e3983c1eb4f689bbd13c3e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stretchable-1.1.6-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7722ccef52e5e72a5deb5d8b81816a17a73e0b15923524e35cccb48502ab727d
MD5 f9f2972aa0f6f02791ddab903e7cfbf3
BLAKE2b-256 41d610a679e0f51800f38091db7c0ba37a23d60a76158d95d904b382c52db31f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stretchable-1.1.6-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 fab2f1ca243a9b113fa4ed24418d9e85d1416f4a3fa083c6ef908b37a656883c
MD5 1c90f0e60de66a743cf2a20d8e2082cf
BLAKE2b-256 690d6ca23cffbd55e76bc31889d87700cc80728ca942d0f31bfc8a0c766d73d9

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