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

Uploaded CPython 3.8+Windows ARM64

stretchable-1.1.7-cp38-abi3-win_amd64.whl (332.5 kB view details)

Uploaded CPython 3.8+Windows x86-64

stretchable-1.1.7-cp38-abi3-win32.whl (322.1 kB view details)

Uploaded CPython 3.8+Windows x86

stretchable-1.1.7-cp38-abi3-musllinux_1_2_x86_64.whl (659.1 kB view details)

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

stretchable-1.1.7-cp38-abi3-musllinux_1_2_aarch64.whl (642.1 kB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ ARM64

stretchable-1.1.7-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (502.0 kB view details)

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

stretchable-1.1.7-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (473.4 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

stretchable-1.1.7-cp38-abi3-macosx_11_0_arm64.whl (434.3 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

stretchable-1.1.7-cp38-abi3-macosx_10_12_x86_64.whl (461.3 kB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: stretchable-1.1.7-cp38-abi3-win_arm64.whl
  • Upload date:
  • Size: 309.6 kB
  • Tags: CPython 3.8+, Windows ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for stretchable-1.1.7-cp38-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 fd919beff3bc158633abe50423fa4bd35fba2d081a80f7858bf0a810af9d9706
MD5 68d5feefe82340429bb1fcf4a6f8c8cf
BLAKE2b-256 78d0cca81cfaffeaaf3ec06770aa3e5da416c088b5c6c32bddd95ba91027524e

See more details on using hashes here.

Provenance

The following attestation bundles were made for stretchable-1.1.7-cp38-abi3-win_arm64.whl:

Publisher: build-publish.yml on mortencombat/stretchable

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: stretchable-1.1.7-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 332.5 kB
  • Tags: CPython 3.8+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for stretchable-1.1.7-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 7608739adcd3db4ac7323d1da8b5630329f6152b57b53834323d9084b2afb076
MD5 8a7dbd6d8df290ee6b768a96aa560424
BLAKE2b-256 7f13a0837818168593323d1c2a146f273f08b986ebf8abba73b45272a1919a31

See more details on using hashes here.

Provenance

The following attestation bundles were made for stretchable-1.1.7-cp38-abi3-win_amd64.whl:

Publisher: build-publish.yml on mortencombat/stretchable

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: stretchable-1.1.7-cp38-abi3-win32.whl
  • Upload date:
  • Size: 322.1 kB
  • Tags: CPython 3.8+, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for stretchable-1.1.7-cp38-abi3-win32.whl
Algorithm Hash digest
SHA256 f7a851ef6f9e350d8719a2ba2627f3cdbb5802ac12f00948e8b271de859fbe04
MD5 c4bddce8f770ccabec629700fd10262a
BLAKE2b-256 47e35274d641eca26e452fa5176fa5b4f629fd7de2596295d59a50edf0e50893

See more details on using hashes here.

Provenance

The following attestation bundles were made for stretchable-1.1.7-cp38-abi3-win32.whl:

Publisher: build-publish.yml on mortencombat/stretchable

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for stretchable-1.1.7-cp38-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 30c2a6fc33576918edd14089f528666dcf674cc859b857d7c31b95221dae05c3
MD5 116c2056ba09e4b27f7f616e963e5e11
BLAKE2b-256 7e59f817a2a13987051a4d4c67bb7427698711a4e0b53e3a9bf2bef9132d8c17

See more details on using hashes here.

Provenance

The following attestation bundles were made for stretchable-1.1.7-cp38-abi3-musllinux_1_2_x86_64.whl:

Publisher: build-publish.yml on mortencombat/stretchable

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for stretchable-1.1.7-cp38-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 63c3f5f770c09d6970723763c84ae448b36c262d3a5e0693d9e8e246a99a191b
MD5 95fe3c6ce1ab586bbe79bebd456597bc
BLAKE2b-256 9bd8cb317bc50e580720be568b31d59c6d8788d15a88850acbd0f54bc98b28cf

See more details on using hashes here.

Provenance

The following attestation bundles were made for stretchable-1.1.7-cp38-abi3-musllinux_1_2_aarch64.whl:

Publisher: build-publish.yml on mortencombat/stretchable

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for stretchable-1.1.7-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 754455bc4b032df51387eb48ea52aaab84049afa3fa05af51e7da7d9f683ee5c
MD5 e30ef3bf812d7d059843db6c81e9f2c2
BLAKE2b-256 e0601031ef1397b37440f58cd6596775535ce9dad7d731712f8ef03e269795cd

See more details on using hashes here.

Provenance

The following attestation bundles were made for stretchable-1.1.7-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build-publish.yml on mortencombat/stretchable

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for stretchable-1.1.7-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 3981fa85667d49896b5f7cb126d50eade0f3c5b01309179d45e57a1b9b45576c
MD5 404a11a7d2ee30752453c9acecf50f0e
BLAKE2b-256 c520b2a7e39c0580631fc7556ab3dc05c09bccc552752b0163d1e2e0a6acb493

See more details on using hashes here.

Provenance

The following attestation bundles were made for stretchable-1.1.7-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: build-publish.yml on mortencombat/stretchable

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for stretchable-1.1.7-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 262db09cb216f788d88611459d1112ce5a38d72f35571dd4215eef00b44d3bfb
MD5 0151d800a5f63636ba7bde9a93ce13ba
BLAKE2b-256 ad089cb0ad9ac4efa4e61f47e0a4ff92e49bfdde1c5ad6bf313c2589f1fb56d3

See more details on using hashes here.

Provenance

The following attestation bundles were made for stretchable-1.1.7-cp38-abi3-macosx_11_0_arm64.whl:

Publisher: build-publish.yml on mortencombat/stretchable

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for stretchable-1.1.7-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 70eaf75a402ad170dd947f05d2cf32096745c6fbfa944c9177e1c84f9f5aa0bb
MD5 5a8a4834a377aa6c6db666aa0648ab6a
BLAKE2b-256 224b8676828e4e5bc31d769f4fdd11a6b207e3acc1de1d8cc1ecda812aebbdc0

See more details on using hashes here.

Provenance

The following attestation bundles were made for stretchable-1.1.7-cp38-abi3-macosx_10_12_x86_64.whl:

Publisher: build-publish.yml on mortencombat/stretchable

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page