Skip to main content

Tag-formatter is a Python Package designed to format strings that based on user-input.

Project description

tag-formatter

Tag-formatter is a Python Package designed to format strings that based on user-input.
For example, tag-formatter can parse something such as:

Hello there, {user}!

Into something like:

Hello there, John!

Installation

You can install tag-formatter using pip.

pip install tag-formatter

Features

  • Highly customizable
    • Uses regex delimiters that you can set.
  • Uses a parser rather than things like str.format
    • Because this was meant for user input, str.format wouldn't work (invalid tags mean KeyErrors)
    • str.replace on the other hand, would be too tedious and limited.
  • Argument parsing for tags
    • Basic and function-based converters
    • Default values for arguments

Example

You can find more examples in the examples folder.

import random
import tagformatter

class User:
    name = 'John'
    age = 21

parser = tagformatter.Parser()

@parser.tag("user")
def user_tag(env):
    return env["user"].name

@user_tag.tag("age")
def user_age_tag(env):
    return env["user"].age

@parser.tag("random", alias="rng")
def rng_tag(env, low: int = 1, high: int = 10):
    return random.randint(low, high)

print(parser.parse("{user} is {user.age} years old. Random number: {random:1, 20}", 
      env={"user": User()}))

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

tag-formatter-1.1.3.tar.gz (5.1 kB view details)

Uploaded Source

File details

Details for the file tag-formatter-1.1.3.tar.gz.

File metadata

  • Download URL: tag-formatter-1.1.3.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for tag-formatter-1.1.3.tar.gz
Algorithm Hash digest
SHA256 5523d40bb5c4c52f0f3924fdf42f18704b2cf54c765dc96df75acee83b54df00
MD5 2896cd8ce599f8ff6c990e583beddb5c
BLAKE2b-256 f2b5f8f58d10a5e1e3f94ec8d56b676e28dbb0914951715f2015c4150ac0948d

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