Skip to main content

Minecraft text formatting, parsing, and rendering

Project description

mctext

Minecraft text formatting, parsing, and rendering library. Features all the exact glyphs used ingame, for the fonts of both pre and post-1.13.

Language Support

Language Package Registry
Rust mctext crates.io
Python mctext PyPI
JavaScript @hexze/mctext npm

Features

  • Builder API - Fluent interface for constructing formatted text
  • Color Support - All 16 named Minecraft colors plus RGB hex colors
  • Style Handling - Bold, italic, underlined, strikethrough, obfuscated
  • Font Rendering - Measure and render text with authentic Minecraft fonts
  • Legacy Support - Parse § formatting codes and JSON chat components

Font Showcase

Font Showcase

Installation

pip install mctext

Quick Start

import mctext

text = mctext.MCText().span("Red ").color("red").then("Bold").color("red").bold().build()

for span in text.spans():
    print(f"{span.text}: {span.color}")

API Reference

MCText

Method Description
MCText() Create empty MCText
MCText.parse(text) Parse legacy § formatted text
MCText.parse_json(json) Parse JSON chat component
span(text) Start building a span, returns SpanBuilder
spans() Get list of text spans
plain_text() Get text without formatting
to_legacy() Convert to legacy § format
to_json() Convert to JSON chat component

SpanBuilder

Method Description
color(color) Set span color (name like "red" or hex "#FF0000")
bold() Make span bold
italic() Make span italic
underlined() Make span underlined
strikethrough() Make span strikethrough
obfuscated() Make span obfuscated
then(text) Add another span and continue building
build() Finish building and return MCText

Span

Property Type Description
text str The text content
color Color Color (named or RGB)
style Style Formatting flags

Color

Property Type Description
name str Color name (named colors only)
code str Format code character (named colors only)
rgb tuple RGB tuple (r, g, b)
r, g, b int Individual components

Style

Property Type Description
bold bool Bold text
italic bool Italic text
underlined bool Underlined text
strikethrough bool Strikethrough text
obfuscated bool Randomized text

Utility Functions

Function Description
parse(text) Shorthand for MCText.parse(text)
parse_json(json) Shorthand for MCText.parse_json(json)
strip_codes(text) Remove all § codes from text
count_visible_chars(text) Count characters excluding format codes
named_colors() Get all 16 named Minecraft colors

Rendering

import mctext

text = mctext.MCText().span("Hello ").color("red").then("World").color("red").bold().build()

fonts = mctext.FontSystem.modern()
options = mctext.LayoutOptions(16.0, None, True)  # size, max_width, shadow
result = mctext.render(fonts, text, 256, 64, options)

# result.width, result.height - dimensions
# result.data() - RGBA bytes

Rendering API

Class/Function Description
FontSystem.modern() Load post-1.13 fonts
FontSystem.legacy() Load pre-1.13 fonts
FontSystem.measure(text, size) Measure text width in pixels
LayoutOptions(size, max_width, shadow) Layout options
render(fonts, text, width, height, options) Render to RGBA buffer

License

MIT

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

mctext-1.2.0.tar.gz (28.3 kB view details)

Uploaded Source

Built Distributions

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

mctext-1.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

mctext-1.2.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (12.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

mctext-1.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

mctext-1.2.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (12.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

mctext-1.2.0-cp311-cp311-win_amd64.whl (12.3 MB view details)

Uploaded CPython 3.11Windows x86-64

mctext-1.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

mctext-1.2.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (12.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

mctext-1.2.0-cp311-cp311-macosx_11_0_arm64.whl (12.8 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

mctext-1.2.0-cp311-cp311-macosx_10_12_x86_64.whl (12.5 MB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

mctext-1.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.5 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

mctext-1.2.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (12.5 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

mctext-1.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.5 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

mctext-1.2.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (12.5 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

File details

Details for the file mctext-1.2.0.tar.gz.

File metadata

  • Download URL: mctext-1.2.0.tar.gz
  • Upload date:
  • Size: 28.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.11.5

File hashes

Hashes for mctext-1.2.0.tar.gz
Algorithm Hash digest
SHA256 153cfb268c816f5f2e6846d5a82b09ee38b08efcab6d09fbe355baa3da919dcb
MD5 b9238b5fafcd841aed5b36751e0972e4
BLAKE2b-256 43a4ee42035aeed602896abe2ea5c0057cb793ab26702a107af083b65277f282

See more details on using hashes here.

File details

Details for the file mctext-1.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for mctext-1.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c15f26ada33c42583a02eafcb91a5517338955448644a1cff32b5b967467ebcb
MD5 d245f6ce2ac192d8c740bcca3e5c211b
BLAKE2b-256 e5b5bd8d1dcd30143130a84c8709a1757ddc55c1d594a1d4df2ce0c26e238243

See more details on using hashes here.

File details

Details for the file mctext-1.2.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for mctext-1.2.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f0171542e6928ac05151fc17982d1eca6591a332df6e24311171a265652a8dae
MD5 41f94a473dd68d569248737974c75bd5
BLAKE2b-256 2cf572c744f926e004f1704b6bdd371e9fb05157bdd08a3e9bfd00d714369342

See more details on using hashes here.

File details

Details for the file mctext-1.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for mctext-1.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b2d2d0f61d1f5cac6d3130bdc90f8461211a6bae4c274307d0079fb560685467
MD5 b25a68475c0b9ee892a989233135ae44
BLAKE2b-256 fd9939a0f5fe8d9b518273b6026e4b0166c9bfb45c7225bee5d68fd9aadbb3ce

See more details on using hashes here.

File details

Details for the file mctext-1.2.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for mctext-1.2.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 efa7801904ac537a9e8c97fae029439397a7ce9b289a0780aa87b7a4ab03e59f
MD5 1d5e891df59c9cb759fa11629c7d7354
BLAKE2b-256 208014b5bf192266141b43b16f1043cc3816be99b2cc87afc7929bfcd4d6a794

See more details on using hashes here.

File details

Details for the file mctext-1.2.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: mctext-1.2.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 12.3 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.11.5

File hashes

Hashes for mctext-1.2.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 a65e989900852a275be1ca984c6acb5d9d2f7d3fecc303fa2f3150370a960f78
MD5 480141c92cf5af81a53d443e556d7394
BLAKE2b-256 26a9989869969b3e3021991ba68ae5639b01ab521d8c8fefee76446c0e0b91f9

See more details on using hashes here.

File details

Details for the file mctext-1.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for mctext-1.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cbd276e3a9f76da4c58f6ae5bb4a06ff914d84f67e7490fc842af65c015f46f8
MD5 d7df855b2592096adb2ec75e462d059b
BLAKE2b-256 9896eec38a41fc5717068e39631db6cebadddb0b5eec5d747e45d61337ef43ef

See more details on using hashes here.

File details

Details for the file mctext-1.2.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for mctext-1.2.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6f49c9279d82047e1b931366f978b830c9831030e5090bd3ca1720302ab78e40
MD5 d17cb1556c9ae095f5993febb8d61ebf
BLAKE2b-256 84775aba2cab9f02582b203760fee69801123a423e990116d1d08ccf04d61d59

See more details on using hashes here.

File details

Details for the file mctext-1.2.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for mctext-1.2.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d28a24906bc3ce20e997f3b9be0d3a7df782c255a6e6087149322a01162c35b6
MD5 f93d6018ab5f3bc4769481f4354da5a1
BLAKE2b-256 65980e556f8a71a2164cc146e8348e2ab520aa035ddb6c3a32629e263cfe56f3

See more details on using hashes here.

File details

Details for the file mctext-1.2.0-cp311-cp311-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for mctext-1.2.0-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 bbf17caf48a1d4cd86c5f9120a880601fd2f13a698ff014eaa71cc1d1a2c2a72
MD5 82ec7721765e9fc953f037e0667a228d
BLAKE2b-256 cb8f12bb76543e132beffe5591ddf4769276ee8074d93331a3f2065153cf33a8

See more details on using hashes here.

File details

Details for the file mctext-1.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for mctext-1.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2fcb5cabd3e34384011b651e86171a39af6fdd9873495171cb76f32684273f57
MD5 f09c00293b5e0cdf4f6641b34068500a
BLAKE2b-256 e08b08fa77e934e93bde0d1d709af8937b1551b4dc3a7053ca25cde7a8ebe281

See more details on using hashes here.

File details

Details for the file mctext-1.2.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for mctext-1.2.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 200846d21ce0d50d87ef0db65ea3003cac865f004e11603d493e6408d738d5f3
MD5 848ff6f48f3cdd0712ab6c0ae45d7764
BLAKE2b-256 83ccd27852ebd0441382e487eca9d2b7688ec92470e2acac9fd98aff68c5aff0

See more details on using hashes here.

File details

Details for the file mctext-1.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for mctext-1.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3a9586c8e8a9a9494ee5b94e90becbce36486b24c1e55cc19ff6c636bad891c9
MD5 ae9e2bbffb4466ce8d1fa4d19149ddb6
BLAKE2b-256 8fbf54816f84ee306715da66d947a023a242a17d904a57912bce6f90ca1682b8

See more details on using hashes here.

File details

Details for the file mctext-1.2.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for mctext-1.2.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0ff5b4ad54f4813e7e2a08329cdbabef01001946606ab460a9d5c98608c8ad98
MD5 c442eb2e1691000d702ccda5c22007d7
BLAKE2b-256 38d78fd25575f2eb6d465d23e6dd613ebea7eff4273d341f6b85fed8ed24094d

See more details on using hashes here.

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