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

Uploaded CPython 3.8+ Windows ARM64

stretchable-1.1.1-cp38-abi3-win_amd64.whl (331.3 kB view details)

Uploaded CPython 3.8+ Windows x86-64

stretchable-1.1.1-cp38-abi3-win32.whl (325.7 kB view details)

Uploaded CPython 3.8+ Windows x86

stretchable-1.1.1-cp38-abi3-musllinux_1_2_x86_64.whl (651.8 kB view details)

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

stretchable-1.1.1-cp38-abi3-musllinux_1_2_aarch64.whl (646.8 kB view details)

Uploaded CPython 3.8+ musllinux: musl 1.2+ ARM64

stretchable-1.1.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (495.4 kB view details)

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

stretchable-1.1.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (481.4 kB view details)

Uploaded CPython 3.8+ manylinux: glibc 2.17+ ARM64

stretchable-1.1.1-cp38-abi3-macosx_11_0_arm64.whl (419.2 kB view details)

Uploaded CPython 3.8+ macOS 11.0+ ARM64

stretchable-1.1.1-cp38-abi3-macosx_10_12_x86_64.whl (442.9 kB view details)

Uploaded CPython 3.8+ macOS 10.12+ x86-64

File details

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

File metadata

File hashes

Hashes for stretchable-1.1.1-cp38-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 e38af16477f0938a2a1b796b1f9f8a08df9975f5d7f07ca14dad10ef76c484db
MD5 faceaef01da14df1d0388f55acce310b
BLAKE2b-256 482427af8fce7f974530144dd8dfbd23cbd28fe55e2f1ddd68716fb09e537e10

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stretchable-1.1.1-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 ad2c715d35f9a6bea102bb3f2c4f269cd5fa7c95b843c318ad1fda32e5390707
MD5 bd5da87df35cb7a183137e1f529a55be
BLAKE2b-256 e25d2dc7d457e3d92fe7893b193a87197a2f51aac10a85d1e8f7fdfbbfe12d66

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for stretchable-1.1.1-cp38-abi3-win32.whl
Algorithm Hash digest
SHA256 c0ddd0d8433ab247f2dcd2b40428e23f78733c9cb1c7d13945a6c106cea32123
MD5 ae8a2a16602cfcdd8e21207514ab25a2
BLAKE2b-256 a71b1f9a329299367a6f914338153568b5ddab503c76e8cdda6f3fd5d0db4dd8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stretchable-1.1.1-cp38-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 6a715c69f2bc7a711d69998f862164943b7f3e59824c38db8f62d30d87da6fac
MD5 ecf5aab0980d9fbf0f056ca2cf32646e
BLAKE2b-256 c66262be80583e3a165ade2b6cdb63f163369dbe1f0c11ced1a6ae5d989c297b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stretchable-1.1.1-cp38-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 3c4789451a13a4368b4957ee03ac78fc2e758dd632f12f9aeb698a2c02cc0114
MD5 e689307e3b900214b7da4c2d5d84bdb2
BLAKE2b-256 99ffd21bde5172fafa59f1a1e756f864a5d747128f53c5927532fa4e6e6feead

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stretchable-1.1.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 50ba2fe81c70703fb1886b456c3a831d0873a049f7721fbaef7bacba31156798
MD5 d92ca777d28bbd834b82b34e970d5b47
BLAKE2b-256 6bd274fdea90854f49e300fe2c07e9b34f95ff1a94f1ccf3a5b30e6963e36907

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stretchable-1.1.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1d02349966e3ab482c7e88ea25cc9efd2a4b04635f67e77bbc4b2cd885565361
MD5 10d83e15bee755c687d64138188b2f0d
BLAKE2b-256 0e94da49c0aaa8b31cfbc99d974bf104c3201830ef7ba681f28070d496a54ce9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stretchable-1.1.1-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fb5cd7fedfec451713ea92d47a094fdaac5a36cdd562747f68c7052e5a8568e8
MD5 d248b452a40e0652c7e8e3c0a2d90ebf
BLAKE2b-256 1c7d55b4d232f491793c6c9166011799b3f3ac90c1e7070c259d4a970dba226f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stretchable-1.1.1-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b097ec1ea7865680f79f6e125b6df4dbef4a2498dc69f1f453f2489d0c3eb89a
MD5 c452b2823aef9cfb29d69a70e719b949
BLAKE2b-256 eb7924066820e9a03ad5acbf047eaa4bd7995300a1dfc9d0c635b2fddffbeefe

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