pyboxen


Namepyboxen JSON
Version 1.3.0 PyPI version JSON
download
home_pagehttps://github.com/savioxavier/pyboxen
SummaryBeautiful, customizable boxes in your terminal using Python
upload_time2024-02-05 21:06:21
maintainer
docs_urlNone
authorSkyascii
requires_python>=3.8.0,<4.0.0
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pyboxen
<!-- markdownlint-disable MD010 MD033 MD001 MD003 -->

> **Create beautiful boxes in the terminal using Python**

[![release](https://badge.fury.io/py/pyboxen.svg)](https://pypi.org/project/pyboxen)
[![downloads](https://img.shields.io/pypi/dm/pyboxen.svg)](https://pypistats.org/packages/pyboxen)
[![github](https://img.shields.io/github/license/savioxavier/pyboxen.svg)](https://github.com/savioxavier/pyboxen/blob/master/LICENSE)
[![total downloads](https://static.pepy.tech/personalized-badge/pyboxen?period=total&units=none&left_color=grey&right_color=blue&left_text=total%20downloads)](https://pepy.tech/project/pyboxen)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

This package is a Python "port" of the popular NPM package [boxen](https://github.com/sindresorhus/boxen/).

It's built on top of [Rich](https://github.com/Textualize/rich/), and features an API that would be familiar to the users of the NPM boxen package.

## 🛠️ Install

Using [pip](https://pypi.org/)

```text
pip install pyboxen
```

---

## 🔗 Usage

- Simplest of simple boxes

```py
from pyboxen import boxen

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

> ![image](https://user-images.githubusercontent.com/38729705/198232802-e41575c6-abd6-416d-9ba6-d1b1c31a2660.png)

- Define options

```py
from pyboxen import boxen

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

> ![image](https://user-images.githubusercontent.com/38729705/198233490-52feeeba-efd3-4fe4-93cf-641d0f58fbf4.png)

- Multiple texts and [Rich Renderables](https://github.com/Textualize/rich#rich-library)

> 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[/]`

```py
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](https://user-images.githubusercontent.com/38729705/198234218-0a4ccfd8-a858-4f84-a99d-f804b926f684.png)

- Title and subtitles

```py
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](https://user-images.githubusercontent.com/38729705/198237935-d01857b8-f61a-42de-b7e5-9fdff59a9739.png)
---

## 🔮 API

### `boxen(*text, **kwargs)`

#### text

A variable (infinite) amount of text strings or [Rich Renderables](https://github.com/Textualize/rich#rich-library), or a mix of both.

#### kwargs

Customize options for the box

Available options include:

```py
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 ☕**

<a href="https://www.buymeacoffee.com/savioxavier">
<img src="https://cdn.buymeacoffee.com/buttons/v2/default-blue.png" height="50px">
</a>

<br>

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

---

## 💫 Attributions and special thanks

- [boxen](https://github.com/sindresorhus/boxen/) - the NPM package I was inspired from
- [rich](https://github.com/Textualize/rich) - for making such an incredibly powerful text customization tool

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/savioxavier/pyboxen",
    "name": "pyboxen",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8.0,<4.0.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "Skyascii",
    "author_email": "savioxavier112@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/46/e7/ade6ddc8ef255e2a3c112c6ab3210f70d26df79dbc2af53922e182bbc42f/pyboxen-1.3.0.tar.gz",
    "platform": null,
    "description": "# pyboxen\n<!-- markdownlint-disable MD010 MD033 MD001 MD003 -->\n\n> **Create beautiful boxes in the terminal using Python**\n\n[![release](https://badge.fury.io/py/pyboxen.svg)](https://pypi.org/project/pyboxen)\n[![downloads](https://img.shields.io/pypi/dm/pyboxen.svg)](https://pypistats.org/packages/pyboxen)\n[![github](https://img.shields.io/github/license/savioxavier/pyboxen.svg)](https://github.com/savioxavier/pyboxen/blob/master/LICENSE)\n[![total downloads](https://static.pepy.tech/personalized-badge/pyboxen?period=total&units=none&left_color=grey&right_color=blue&left_text=total%20downloads)](https://pepy.tech/project/pyboxen)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n\nThis package is a Python \"port\" of the popular NPM package [boxen](https://github.com/sindresorhus/boxen/).\n\nIt's built on top of [Rich](https://github.com/Textualize/rich/), and features an API that would be familiar to the users of the NPM boxen package.\n\n## \ud83d\udee0\ufe0f Install\n\nUsing [pip](https://pypi.org/)\n\n```text\npip install pyboxen\n```\n\n---\n\n## \ud83d\udd17 Usage\n\n- Simplest of simple boxes\n\n```py\nfrom pyboxen import boxen\n\nprint(boxen(\"Python is cool!\"))\n```\n\n> ![image](https://user-images.githubusercontent.com/38729705/198232802-e41575c6-abd6-416d-9ba6-d1b1c31a2660.png)\n\n- Define options\n\n```py\nfrom pyboxen import boxen\n\nprint(\n    boxen(\n        \"Python is cool!\",\n        padding=1,\n        margin=1,\n        color=\"cyan\",\n    )\n)\n```\n\n> ![image](https://user-images.githubusercontent.com/38729705/198233490-52feeeba-efd3-4fe4-93cf-641d0f58fbf4.png)\n\n- Multiple texts and [Rich Renderables](https://github.com/Textualize/rich#rich-library)\n\n> You can even use Rich's special color style syntax for the text, title and subtitle as well\n>\n> Example: `[red]Hello[/red] [bold italic]World[/]`\n\n```py\nfrom pyboxen import boxen\n\n# Multiple texts\n\nprint(\n    boxen(\n        \"Python is cool!\",\n        \"Yeah it totally is!\",\n        \"I [red]:heart:[/red]  [yellow bold]Python[/]!\",  # You can even use Rich syntax here too!\n        padding=1,\n        margin=1,\n        color=\"cyan\",\n    )\n)\n\n# Rich renderables, with a mix of strings and renderables\n\nfrom rich.table import Table\n\ntable = Table(show_header=True, header_style=\"bold magenta\")\n\ntable.add_column(\"Date\", style=\"dim\", width=12)\ntable.add_column(\"Title\")\ntable.add_column(\"Production Budget\", justify=\"right\")\ntable.add_column(\"Box Office\", justify=\"right\")\ntable.add_row(\n    \"Dec 20, 2019\", \"Star Wars: The Rise of Skywalker\", \"$275,000,000\", \"$375,126,118\"\n)\ntable.add_row(\n    \"May 25, 2018\",\n    \"[red]Solo[/red]: A Star Wars Story\",\n    \"$275,000,000\",\n    \"$393,151,347\",\n)\ntable.add_row(\n    \"Dec 15, 2017\",\n    \"Star Wars Ep. VIII: The Last Jedi\",\n    \"$262,000,000\",\n    \"[bold]$1,332,539,889[/bold]\",\n)\n\nprint(\n    boxen(\n        \"Python is cool!\",\n        table\n    )\n)\n```\n\n> ![image](https://user-images.githubusercontent.com/38729705/198234218-0a4ccfd8-a858-4f84-a99d-f804b926f684.png)\n\n- Title and subtitles\n\n```py\nfrom pyboxen import boxen\n\nprint(\n    boxen(\n        \"Titles and subtitles!\",\n        title=\"Hello, [black on cyan] World [/]\",\n        subtitle=\"Cool subtitle goes here\",\n        subtitle_alignment=\"center\",\n        color=\"yellow\",\n        padding=1,\n    )\n)\n```\n\n> ![image](https://user-images.githubusercontent.com/38729705/198237935-d01857b8-f61a-42de-b7e5-9fdff59a9739.png)\n---\n\n## \ud83d\udd2e API\n\n### `boxen(*text, **kwargs)`\n\n#### text\n\nA variable (infinite) amount of text strings or [Rich Renderables](https://github.com/Textualize/rich#rich-library), or a mix of both.\n\n#### kwargs\n\nCustomize options for the box\n\nAvailable options include:\n\n```py\ncolor: str = \"white\",\nstyle: Literal[\"ascii\", \"ascii2\", \"ascii_double_head\", \"square\", \"square_double_head\", \"minimal\", \"horizontals\", \"rounded\", \"heavy\", \"double\"] = \"rounded\"\npadding: Union[int, tuple[int]] = 0,\nmargin: Union[int, tuple[int]] = 0,\ntext_alignment: Literal[\"left\", \"center\", \"right\"] = \"center\",\nbox_alignment: Literal[\"left\", \"center\", \"right\"] = \"left\",\ntitle: str = None,\ntitle_alignment: Literal[\"left\", \"center\", \"right\"] = \"left\",\nsubtitle: str = None,\nsubtitle_alignment: Literal[\"left\", \"center\", \"right\"] = \"left\",\nfullwidth: bool = False,\n```\n\n#### color\n\nThe color of the box in color or hex code starting with #, defaults to white\n\n#### style\n\nThe style of the box, defaults to rounded\n\n#### padding\n\nThe padding between the text and the box in int or tuple of ints, defaults to 0\n\n#### margin\n\nThe margin around the box in int or tuple of ints, defaults to 0\n\n#### text_alignment\n\nThe alignment of the text inside the box, defaults to center\n\n#### box_alignment\n\nThe alignment of the box in the terminal, defaults to left\n\n#### title\n\nThe title of the box, displayed on the top of the box, if provided\n\n#### title_alignment\n\nThe alignment of the title, defaults to left\n\n#### subtitle\n\nThe subtitle of the box, displayed on the bottom of the box, if provided\n\n#### subtitle_alignment\n\nThe alignment of the subtitle, defaults to left\n\n#### fullwidth\n\nIf True, the box will expand to fill the entire terminal width, defaults to False\n\n> **Note**\n> `padding` and `margin` attributes can be either an int, a tuple of ints (with a total of either 2 elements or 4 elements)\n> Example:\n>\n> `2` - all of top, right, bottom, left\n>\n> `(2, 4)` - (top = bottom, right = left)\n>\n> `(2, 4, 6, 8)` - (top, right, bottom, left)\n\n---\n\n## \u2764\ufe0f Support\n\nYou can support further development of this project by **giving it a \ud83c\udf1f** and help me make even better stuff in the future by **buying me a \u2615**\n\n<a href=\"https://www.buymeacoffee.com/savioxavier\">\n<img src=\"https://cdn.buymeacoffee.com/buttons/v2/default-blue.png\" height=\"50px\">\n</a>\n\n<br>\n\n**Also, if you liked this repo, consider checking out my other projects, that would be real cool!**\n\n---\n\n## \ud83d\udcab Attributions and special thanks\n\n- [boxen](https://github.com/sindresorhus/boxen/) - the NPM package I was inspired from\n- [rich](https://github.com/Textualize/rich) - for making such an incredibly powerful text customization tool\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Beautiful, customizable boxes in your terminal using Python",
    "version": "1.3.0",
    "project_urls": {
        "Homepage": "https://github.com/savioxavier/pyboxen",
        "Repository": "https://github.com/savioxavier/pyboxen"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "17c0ff96b0e84ba004123eddd0fb2299cc6499cff62eb6c126d468fc05181ab5",
                "md5": "cda4fbc0828bfcc71ce3c21092e1242c",
                "sha256": "ac799533bbdb0a4f4a7c3b8723607dbe3aed3d293d3863e178064027f8177c9c"
            },
            "downloads": -1,
            "filename": "pyboxen-1.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "cda4fbc0828bfcc71ce3c21092e1242c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8.0,<4.0.0",
            "size": 6789,
            "upload_time": "2024-02-05T21:06:19",
            "upload_time_iso_8601": "2024-02-05T21:06:19.479481Z",
            "url": "https://files.pythonhosted.org/packages/17/c0/ff96b0e84ba004123eddd0fb2299cc6499cff62eb6c126d468fc05181ab5/pyboxen-1.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "46e7ade6ddc8ef255e2a3c112c6ab3210f70d26df79dbc2af53922e182bbc42f",
                "md5": "f5c29874811e5b4e1d5d009ee4092cb0",
                "sha256": "f12e6c656769f9d6aa1dd5d11688a62ed12da9dcebfa22a242103c610130b948"
            },
            "downloads": -1,
            "filename": "pyboxen-1.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "f5c29874811e5b4e1d5d009ee4092cb0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8.0,<4.0.0",
            "size": 5943,
            "upload_time": "2024-02-05T21:06:21",
            "upload_time_iso_8601": "2024-02-05T21:06:21.233358Z",
            "url": "https://files.pythonhosted.org/packages/46/e7/ade6ddc8ef255e2a3c112c6ab3210f70d26df79dbc2af53922e182bbc42f/pyboxen-1.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-05 21:06:21",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "savioxavier",
    "github_project": "pyboxen",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pyboxen"
}
        
Elapsed time: 0.22827s