Skip to main content

Beautiful, customizable boxes in your terminal using Python

Project description

pyboxen

Create beautiful boxes in the terminal using Python

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 boxen

🔗 Usage

  • Simplest of simple boxes
from boxen import boxen

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

image

  • Define options
from boxen 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 boxen 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 boxen 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: str = "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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyboxen-0.1.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

pyboxen-0.1.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file pyboxen-0.1.0.tar.gz.

File metadata

  • Download URL: pyboxen-0.1.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.14 CPython/3.10.5 Windows/10

File hashes

Hashes for pyboxen-0.1.0.tar.gz
Algorithm Hash digest
SHA256 336a6c1f6fbb36f87a412c1412335a135131d4857b0067bf427d62de8a8b0813
MD5 ec1e92194310ebf8c5e9ddfab7887180
BLAKE2b-256 283dd5001020b20e527214f1f19cc54b5e9db9e5344e5596a2e90f1d8b6ade09

See more details on using hashes here.

File details

Details for the file pyboxen-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pyboxen-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.14 CPython/3.10.5 Windows/10

File hashes

Hashes for pyboxen-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d975ac450a12be85c285715b2c8d57baa98245b0ca9f9cceb6374c905f3e25d5
MD5 c45661c15c57e1f6550e06677b8818da
BLAKE2b-256 d1cfc9fe780cbf141a901fe46d351a6d319d9fe03ec94a346b461979d7cb3395

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