Skip to main content

pyboxen

Create beautiful boxes in the terminal using Python

release downloads github total downloads Code style: black

This package is a Python "port" of the popular NPM package boxen.

It's built on top of Rich, and features an API that would be familiar to the users of the NPM boxen package.

🛠️ Install

Using pip

pip install pyboxen

🔗 Usage

  • Simplest of simple boxes
from pyboxen import boxen

print(boxen("Python is cool!"))

image

  • Define options
from pyboxen import boxen

print(
    boxen(
        "Python is cool!",
        padding=1,
        margin=1,
        color="cyan",
    )
)

image

You can even use Rich's special color style syntax for the text, title and subtitle as well

Example: [red]Hello[/red] [bold italic]World[/]

from pyboxen import boxen

# Multiple texts

print(
    boxen(
        "Python is cool!",
        "Yeah it totally is!",
        "I [red]:heart:[/red]  [yellow bold]Python[/]!",  # You can even use Rich syntax here too!
        padding=1,
        margin=1,
        color="cyan",
    )
)

# Rich renderables, with a mix of strings and renderables

from rich.table import Table

table = Table(show_header=True, header_style="bold magenta")

table.add_column("Date", style="dim", width=12)
table.add_column("Title")
table.add_column("Production Budget", justify="right")
table.add_column("Box Office", justify="right")
table.add_row(
    "Dec 20, 2019", "Star Wars: The Rise of Skywalker", "$275,000,000", "$375,126,118"
)
table.add_row(
    "May 25, 2018",
    "[red]Solo[/red]: A Star Wars Story",
    "$275,000,000",
    "$393,151,347",
)
table.add_row(
    "Dec 15, 2017",
    "Star Wars Ep. VIII: The Last Jedi",
    "$262,000,000",
    "[bold]$1,332,539,889[/bold]",
)

print(
    boxen(
        "Python is cool!",
        table
    )
)

image

  • Title and subtitles
from pyboxen import boxen

print(
    boxen(
        "Titles and subtitles!",
        title="Hello, [black on cyan] World [/]",
        subtitle="Cool subtitle goes here",
        subtitle_alignment="center",
        color="yellow",
        padding=1,
    )
)

image


🔮 API

boxen(*text, **kwargs)

text

A variable (infinite) amount of text strings or Rich Renderables, or a mix of both.

kwargs

Customize options for the box

Available options include:

color: str = "white",
style: Literal["ascii", "ascii2", "ascii_double_head", "square", "square_double_head", "minimal", "horizontals", "rounded", "heavy", "double"] = "rounded"
padding: Union[int, tuple[int]] = 0,
margin: Union[int, tuple[int]] = 0,
text_alignment: Literal["left", "center", "right"] = "center",
box_alignment: Literal["left", "center", "right"] = "left",
title: str = None,
title_alignment: Literal["left", "center", "right"] = "left",
subtitle: str = None,
subtitle_alignment: Literal["left", "center", "right"] = "left",
fullwidth: bool = False,

color

The color of the box in color or hex code starting with #, defaults to white

style

The style of the box, defaults to rounded

padding

The padding between the text and the box in int or tuple of ints, defaults to 0

margin

The margin around the box in int or tuple of ints, defaults to 0

text_alignment

The alignment of the text inside the box, defaults to center

box_alignment

The alignment of the box in the terminal, defaults to left

title

The title of the box, displayed on the top of the box, if provided

title_alignment

The alignment of the title, defaults to left

subtitle

The subtitle of the box, displayed on the bottom of the box, if provided

subtitle_alignment

The alignment of the subtitle, defaults to left

fullwidth

If True, the box will expand to fill the entire terminal width, defaults to False

Note padding and margin attributes can be either an int, a tuple of ints (with a total of either 2 elements or 4 elements) Example:

2 - all of top, right, bottom, left

(2, 4) - (top = bottom, right = left)

(2, 4, 6, 8) - (top, right, bottom, left)


❤️ Support

You can support further development of this project by giving it a 🌟 and help me make even better stuff in the future by buying me a ☕


Also, if you liked this repo, consider checking out my other projects, that would be real cool!


💫 Attributions and special thanks

  • boxen - the NPM package I was inspired from
  • rich - for making such an incredibly powerful text customization tool

Metadata

Release files for pyboxen 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyboxen 1.3.0
File Size Uploaded Provenance Actions
pyboxen-1.3.0.tar.gz 5.9 kB Without provenance Details for pyboxen-1.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyboxen 1.3.0
File Interpreter ABI Platform Actions
pyboxen-1.3.0-py3-none-any.whl Python 3 none any Details for pyboxen-1.3.0-py3-none-any.whl

Total release size: 12.7 kB

Release files / pyboxen-1.3.0.tar.gz

Download URL pyboxen-1.3.0.tar.gz
Size 5.9 kB
Tags Source
SHA-256 checksum
How to use checksums
f12e6c656769f9d6aa1dd5d11688a62ed12da9dcebfa22a242103c610130b948
BLAKE2b-256 checksum
How to use checksums
46e7ade6ddc8ef255e2a3c112c6ab3210f70d26df79dbc2af53922e182bbc42f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.11.4 Windows/10

Release files / pyboxen-1.3.0-py3-none-any.whl

Download URL pyboxen-1.3.0-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ac799533bbdb0a4f4a7c3b8723607dbe3aed3d293d3863e178064027f8177c9c
BLAKE2b-256 checksum
How to use checksums
17c0ff96b0e84ba004123eddd0fb2299cc6499cff62eb6c126d468fc05181ab5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.11.4 Windows/10

Security for pyboxen 1.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page