Skip to main content

A Python library that allows you to retroactively modify printed content in the terminal using ANSI escape sequences.

Project description

Mutable Print Documentation

A Python library that allows you to retroactively modify printed content in the terminal using ANSI escape sequences.

Installation

pip install mutable-print

Credits

Created and maintained by the mutable-print development team.

License

This project is licensed under the MIT License.

Overview

mutable_print is a replacement for Python's built-in print() function that stores printed content and allows you to modify it after it has been displayed. This is particularly useful for creating dynamic terminal UIs, progress bars, and loading animations.

API Reference

Constructor

mutable_print(
    *args: Any,
    sep: str = ' ',
    end: str = '\n',
    file: Optional[TextIO] = None,
    flush: bool = False
) -> mutable_print

Creates a new mutable print object with the same signature as the built-in print() function.

Parameters:

  • *args: Any - Values to print
  • sep: str - String inserted between values (default: ' ')
  • end: str - String appended after the last value (default: '\n')
  • file: Optional[TextIO] - File object to write to (default: sys.stdout)
  • flush: bool - Whether to forcibly flush the stream (default: False)

Returns: mutable_print instance

Methods

__call__(*args: Any, sep: str = ' ', end: str = '\n') -> None

Update the print content with new values.

mutable = mutable_print("Hello")
mutable("World")

Parameters:

  • *args: Any - New values to print
  • sep: str - New separator between values (default: ' ')
  • end: str - New string appended after the last value (default: '\n')

replace(old: str, new: str, count: int = -1) -> mutable_print

Replace occurrences of a substring in the content.

mutable = mutable_print("Hello World")
mutable.replace("World", "Python")

Parameters:

  • old: str - Substring to replace
  • new: str - Replacement string
  • count: int - Maximum number of occurrences to replace (default: -1 for all)

Returns: mutable_print - Self for method chaining

append(*text: str) -> mutable_print

Append text to the end of the content.

mutable = mutable_print("Hello")
mutable.append("World", "!")

Parameters:

  • *text: str - Text strings to append

Returns: mutable_print - Self for method chaining

prepend(*text: str) -> mutable_print

Prepend text to the beginning of the content.

mutable = mutable_print("World")
mutable.prepend("Hello", " ")

Parameters:

  • *text: str - Text strings to prepend

Returns: mutable_print - Self for method chaining

clear() -> mutable_print

Clear the content completely.

mutable = mutable_print("Hello World")
mutable.clear()

Returns: mutable_print - Self for method chaining

set(*text: str) -> mutable_print

Replace the entire content with new text.

mutable = mutable_print("Old text")
mutable.set("New", "text")

Parameters:

  • *text: str - Text strings to set as new content

Returns: mutable_print - Self for method chaining

upper() -> mutable_print

Convert all content to uppercase.

mutable = mutable_print("hello")
mutable.upper()

Returns: mutable_print - Self for method chaining

lower() -> mutable_print

Convert all content to lowercase.

mutable = mutable_print("HELLO")
mutable.lower()

Returns: mutable_print - Self for method chaining

regex_replace(pattern: str | re.Pattern[str], replacement: str, flags: int = 0) -> mutable_print

Replace content using regular expressions.

mutable = mutable_print("Hello123World456")
mutable.regex_replace(r'\d+', '-')

Parameters:

  • pattern: str | re.Pattern[str] - Regular expression pattern to match (string or compiled pattern)
  • replacement: str - Replacement string (can include backreferences)
  • flags: int - Optional regex flags (e.g., re.IGNORECASE) (default: 0)

Returns: mutable_print - Self for method chaining

get() -> str

Get the current content as a string.

mutable = mutable_print("Hello World")
content = mutable.get()

Returns: str - Current content string

Method Chaining

All modifier methods return self, allowing you to chain multiple operations:

mutable = mutable_print("hello world")
mutable.upper().replace("WORLD", "PYTHON").append("!")

How It Works

mutable_print uses ANSI escape sequences to move the cursor up and clear lines, then reprints all content from the modified point forward. This creates the illusion of modifying previously printed content while maintaining compatibility with standard terminal output.

Limitations

  • Works best in terminals that support ANSI escape sequences
  • May not work properly in non-interactive environments or certain IDEs
  • Performance may degrade with a large number of mutable print objects

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

mutable_print-1.0.0.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

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

mutable_print-1.0.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file mutable_print-1.0.0.tar.gz.

File metadata

  • Download URL: mutable_print-1.0.0.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mutable_print-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b0cb933b0a7addbbd0f6a75b922e452f7c239c7888d9d0224319698140fadfaa
MD5 af3f146d5aaf1ad260f35713dd981bbc
BLAKE2b-256 ac4eef46396677e849161073b7dbe38638873ec2f3f7282a49670b9fea5ebc0d

See more details on using hashes here.

Provenance

The following attestation bundles were made for mutable_print-1.0.0.tar.gz:

Publisher: release.yaml on PcoiDev/mutable-print

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

File details

Details for the file mutable_print-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: mutable_print-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mutable_print-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 58812fa1446fa95c0292371b3e88d5749bf85427ee498d239f338f1e87e81e48
MD5 984dcc240238c93be3b6c943ab770a24
BLAKE2b-256 44f4ce90252d711a42f8d808fbaba74f4b7a48fdacc852631609b59818c1223b

See more details on using hashes here.

Provenance

The following attestation bundles were made for mutable_print-1.0.0-py3-none-any.whl:

Publisher: release.yaml on PcoiDev/mutable-print

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