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.

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

Uploaded CPython 3.8+ Windows ARM64

stretchable-1.1.2-cp38-abi3-win_amd64.whl (331.4 kB view details)

Uploaded CPython 3.8+ Windows x86-64

stretchable-1.1.2-cp38-abi3-win32.whl (325.6 kB view details)

Uploaded CPython 3.8+ Windows x86

stretchable-1.1.2-cp38-abi3-musllinux_1_2_x86_64.whl (651.4 kB view details)

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

stretchable-1.1.2-cp38-abi3-musllinux_1_2_aarch64.whl (646.7 kB view details)

Uploaded CPython 3.8+ musllinux: musl 1.2+ ARM64

stretchable-1.1.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (494.8 kB view details)

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

stretchable-1.1.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (480.8 kB view details)

Uploaded CPython 3.8+ manylinux: glibc 2.17+ ARM64

stretchable-1.1.2-cp38-abi3-macosx_11_0_arm64.whl (427.2 kB view details)

Uploaded CPython 3.8+ macOS 11.0+ ARM64

stretchable-1.1.2-cp38-abi3-macosx_10_12_x86_64.whl (461.1 kB view details)

Uploaded CPython 3.8+ macOS 10.12+ x86-64

File details

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

File metadata

File hashes

Hashes for stretchable-1.1.2-cp38-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 1673134cd35883bc83c2bbfe62b5f426b037ac2ace972ccd492c0a231f121fd0
MD5 f8b9df36bdff48a8cda1562acb6a239f
BLAKE2b-256 ae3e8bd3643393dcb37802f745ba1b6806ffec87995e2e6ca16b54e6f2e1388c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stretchable-1.1.2-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 a05024f114bbb1b88cbffef8649d32f7bd4b5dcf2b859fda4fc0662827e90481
MD5 dfb2b6ed07492f80eb2e8634ae27a671
BLAKE2b-256 ec9262f4429aef23df125a117233a53ffb723de1ca4a4cbfb096d308aa14f0a7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: stretchable-1.1.2-cp38-abi3-win32.whl
  • Upload date:
  • Size: 325.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.2-cp38-abi3-win32.whl
Algorithm Hash digest
SHA256 1c31c4d714437b359a98abb0c4df5265aae7d581c41c68964355b7501aaf976d
MD5 598bafd8f8cf7050b2d8d815ed4a4596
BLAKE2b-256 008094eabf699c47224d123ccb35caf1d987e748c4c9cb6975db8bf5db8aea19

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stretchable-1.1.2-cp38-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 ad30f47becfd296394e693af11631ce5d5aa5456267fd66f19ebaeb2800f77f6
MD5 070240038af4777fcd5aead2354d2747
BLAKE2b-256 b37dd826a724253c071f263dd7dabdfebc368564546d3cb95068bab0766f0662

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stretchable-1.1.2-cp38-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 c16a0ec19e7d368c1303a04b2a840ffde3118ca7077a7302441f8a82c0f1f594
MD5 fac45bc6f246100de48e41adfab90022
BLAKE2b-256 3753a95cbd7047262ae50e5107f29d4825d6365b75355deb0d890f4a3f16f0b1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stretchable-1.1.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2c68a3aadf81359c0a580b500316b840388791120a646cf90b11e844119b9577
MD5 a48e150e42587812c45e0fc1920c437b
BLAKE2b-256 f02ceed425e31773a68a17d7f4240fa7ebeb013321dafb631212ec50667f234b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stretchable-1.1.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 543f9fda816ee299e43a915756ee11f93ac46e8a54eff026fba8a244adbcafb7
MD5 c01b3e704b54061c2a81d25d672e5ce7
BLAKE2b-256 1ee49028b9174bf202b8b4d2ac2ac18e74baf22c57581600f87de44554bbf385

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stretchable-1.1.2-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8a32b00102f14521da370f9c630a096c2069b0b724ea41d0fe79134b68fd1f85
MD5 0bf93fd09849d0cbd1b0d5b86cfd55c3
BLAKE2b-256 e3bc2e95e6e5348d8133f13c6e4ca286cec6d1603953d546ff1d3aaf46f76b44

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stretchable-1.1.2-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 af57bdbe411bf90a6bb7b02d6ba3ce62b5a7be9f791299cd147eb2b3efa49681
MD5 dcc5cd2773cb16429663d3a79d7f6206
BLAKE2b-256 4dce8ef847f59f1b4b6de4a73010a4bee165024f62cb0ec9469876f57867e376

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