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 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 Grid/Flexbox 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 attrs

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 child node
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 ~650 tests, the majority of which are run using Selenium with the Chrome WebDriver, and the complete test suite can take ~20 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.0.0-cp38-abi3-win_arm64.whl (306.9 kB view hashes)

Uploaded CPython 3.8+ Windows ARM64

stretchable-1.0.0-cp38-abi3-win_amd64.whl (332.1 kB view hashes)

Uploaded CPython 3.8+ Windows x86-64

stretchable-1.0.0-cp38-abi3-win32.whl (292.4 kB view hashes)

Uploaded CPython 3.8+ Windows x86

stretchable-1.0.0-cp38-abi3-musllinux_1_2_x86_64.whl (1.6 MB view hashes)

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

stretchable-1.0.0-cp38-abi3-musllinux_1_2_aarch64.whl (1.5 MB view hashes)

Uploaded CPython 3.8+ musllinux: musl 1.2+ ARM64

stretchable-1.0.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.4 MB view hashes)

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

stretchable-1.0.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.4 MB view hashes)

Uploaded CPython 3.8+ manylinux: glibc 2.17+ ARM64

stretchable-1.0.0-cp38-abi3-macosx_11_0_arm64.whl (457.0 kB view hashes)

Uploaded CPython 3.8+ macOS 11.0+ ARM64

stretchable-1.0.0-cp38-abi3-macosx_10_7_x86_64.whl (496.7 kB view hashes)

Uploaded CPython 3.8+ macOS 10.7+ x86-64

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