Skip to main content

A tiny library to make your outputs more beautiful

Project description

prettyfmt

prettyfmt is a tiny library to make your outputs, logs, and __str__() representations slightly more beautiful.

It offers simple but general functions for formatting and abbreviating objects and dataclasses, dicts, words and phrases, filenames, titles, long strings, timestamps, ages, and sizes.

Simply a more convenient wrapper around humanize, humanfriendly, and strif.

from prettyfmt import *

# Simple abbreviations of objects:
abbrev_obj({"a": "very " * 100 + "long", "b": 23})
🢂 "{a='very very very very very very very very very very very very ver…', b=23}"

# Abbreviate but don't break words. Combine with slugifiers.
abbrev_on_words("very " * 100 + "long", 30)
🢂 'very very very very very very…'

# My favorite, very good for abbreviating a long title to get a shorter one,
# or good filename.
abbrev_phrase_in_middle("very " * 100 + "long", 40)
🢂 'very very very very … very very very long'

# Ages in seconds or deltas.
fmt_age(60 * 60 * 24 * 23)
🢂 '3 weeks and 2 days ago'

fmt_age(60 * 60 *24 * 23, brief=True)
🢂 '3w ago'

# Sizes
fmt_size_human(12000000)
🢂 '11.4M'

fmt_size_dual(12000000)
🢂 '11.4M (12000000 bytes)'

# Helpful making __str__() methods or printing output:
fmt_words("Hello", None, "", "world!")
🢂 'Hello world!'

fmt_paras(fmt_words("Hello", "world!"), "", "Goodbye.")
🢂 'Hello world!\n\nGoodbye.'

# Example of `abbrev_obj` to customize __str__().
# Allows sorting and truncating based on key and value.
@dataclass
class MyThing:
   file_path: Path
   title: str
   url: str
   body: str

   def __str__(self) -> str:
      return abbrev_obj(
            self,
            # Put an abbreviated title first, then the file path, then the url.
            key_filter={
               "title": 64,
               "file_path": 0,
               "url": 128,
            },
      )

See pydoc for details.

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

prettyfmt-0.1.1.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

prettyfmt-0.1.1-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file prettyfmt-0.1.1.tar.gz.

File metadata

  • Download URL: prettyfmt-0.1.1.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for prettyfmt-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2c99a1ec23f6abba98c86b2ff8072fbc9390451a4696513f254614dbc77edb26
MD5 bdf1e98931436c533ccf070a9e749cf3
BLAKE2b-256 3a2f9fc893c856f4066b5984fa4016e6b2c08841bc2b429bd7a62bbab1f121f9

See more details on using hashes here.

Provenance

The following attestation bundles were made for prettyfmt-0.1.1.tar.gz:

Publisher: publish.yml on jlevy/prettyfmt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file prettyfmt-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: prettyfmt-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for prettyfmt-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6a063c5b9a2372fdeec541d9461a1d580f7613bb14c029edea4cc439d3a92d73
MD5 51a138f98e27d14724be5f2e611489cb
BLAKE2b-256 193aa9f5d7869709fa4eb8097f15b47692f71b6f88245a82f29e814c7e8716cf

See more details on using hashes here.

Provenance

The following attestation bundles were made for prettyfmt-0.1.1-py3-none-any.whl:

Publisher: publish.yml on jlevy/prettyfmt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page