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.1.2.tar.gz (29.2 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.1.2-cp313-cp313-manylinux_2_24_x86_64.whl (12.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.24+ x86-64

mctext-1.1.2-cp313-cp313-manylinux_2_24_aarch64.whl (12.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.24+ ARM64

mctext-1.1.2-cp312-cp312-manylinux_2_24_x86_64.whl (12.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.24+ x86-64

mctext-1.1.2-cp312-cp312-manylinux_2_24_aarch64.whl (12.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.24+ ARM64

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

Uploaded CPython 3.11Windows x86-64

mctext-1.1.2-cp311-cp311-manylinux_2_24_x86_64.whl (12.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.24+ x86-64

mctext-1.1.2-cp311-cp311-manylinux_2_24_aarch64.whl (12.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.24+ ARM64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 10.12+ x86-64

mctext-1.1.2-cp310-cp310-manylinux_2_24_x86_64.whl (12.5 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.24+ x86-64

mctext-1.1.2-cp310-cp310-manylinux_2_24_aarch64.whl (12.5 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.24+ ARM64

mctext-1.1.2-cp39-cp39-manylinux_2_24_x86_64.whl (12.5 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.24+ x86-64

mctext-1.1.2-cp39-cp39-manylinux_2_24_aarch64.whl (12.5 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.24+ ARM64

File details

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

File metadata

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

File hashes

Hashes for mctext-1.1.2.tar.gz
Algorithm Hash digest
SHA256 f68d24c6826f702638294dbedb191dfeeb77036108b502eb6d2daf66b8436ee2
MD5 31f2a791a73060dde36f947dfa6bd1f7
BLAKE2b-256 cff0411f221314af47543ae4a8fc1fba466c4f6f1b87a613b3eff2b851f72651

See more details on using hashes here.

File details

Details for the file mctext-1.1.2-cp313-cp313-manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for mctext-1.1.2-cp313-cp313-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 4f797765745992bafbe491bc859dfb773d3021d71159a518762b0975a3d3ede0
MD5 2bddb5ae9eb4f77492bf55bcb81f2250
BLAKE2b-256 55e502cfdd507430a99f428a0b94b7273d2fb7e573821e7509012bb00baf6a1b

See more details on using hashes here.

File details

Details for the file mctext-1.1.2-cp313-cp313-manylinux_2_24_aarch64.whl.

File metadata

File hashes

Hashes for mctext-1.1.2-cp313-cp313-manylinux_2_24_aarch64.whl
Algorithm Hash digest
SHA256 aea913e8ce99d5ba3630dc10af22ce5115bb8648e81dac28dfcf6840dd6c02db
MD5 90b1a19b3b31f61ecd47c32eb9943ce5
BLAKE2b-256 93d8891806e02b1082220cfbd6be7cbc6210acab44664a968610a5d38e002b66

See more details on using hashes here.

File details

Details for the file mctext-1.1.2-cp312-cp312-manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for mctext-1.1.2-cp312-cp312-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 370901f23eb3c15d0d1111f5664edd5a4bbe50e66a78465868f59f7e53de100c
MD5 fe19a3bba1a933c12ef9c5bc38cbc95e
BLAKE2b-256 a6f18cbe996c5292cac17fa251c73c22926b0c6b16e056c63fff6e5a796fc467

See more details on using hashes here.

File details

Details for the file mctext-1.1.2-cp312-cp312-manylinux_2_24_aarch64.whl.

File metadata

File hashes

Hashes for mctext-1.1.2-cp312-cp312-manylinux_2_24_aarch64.whl
Algorithm Hash digest
SHA256 b3be7c4325fce909476f02c80d825f8b809996706501910e1ba62608656533ca
MD5 89a0a059f1b93b3da4497db005b53007
BLAKE2b-256 afead5f968fbbe55ac7c82d4d8a3a5f92f42550c7e01fe1811b1cb180bee0ba9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mctext-1.1.2-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.2

File hashes

Hashes for mctext-1.1.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 6f308315018193ed99f25d41c1aff964d4573c1096f647c04d1975409d047992
MD5 88987a6502525cfa9cda3aac94070e95
BLAKE2b-256 befa4e3fc725c4a7f3fd0d97d4f83c9eb3f3244bbba3a69577f09e8add941f18

See more details on using hashes here.

File details

Details for the file mctext-1.1.2-cp311-cp311-manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for mctext-1.1.2-cp311-cp311-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 5441bd3ceaabbc04fec9896992f6fa446b1c6c9dd01582d2a8683b843e6ce561
MD5 17ef50b33cb3c4e210c474a38ad04c09
BLAKE2b-256 526f27b5cc2c9077faf29d5b40c69c483ed0cfaff58ac3ad7e6e8e386011a8d4

See more details on using hashes here.

File details

Details for the file mctext-1.1.2-cp311-cp311-manylinux_2_24_aarch64.whl.

File metadata

File hashes

Hashes for mctext-1.1.2-cp311-cp311-manylinux_2_24_aarch64.whl
Algorithm Hash digest
SHA256 f8e4a8e8884710428e263351603ed068e41c6facf5b04ed9e47836f850bbea1b
MD5 a88d713e929b7c234bc5abb6a8f241bc
BLAKE2b-256 3e45bdd8fd8dd99514466b46aec25e9db523b39aef3748498d586ff9b8ea4f20

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mctext-1.1.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3fe9aa29be47f544b344cd8b2be8c6979c206d70c28b4a993908cc937ae274df
MD5 c07bbf4e66692d2f81fa9978ff85ebe6
BLAKE2b-256 2f244121a973528c86eec652f9a0e2f7a7d2b8704d95b6ab1229125804e1efe4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mctext-1.1.2-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 aa79bcc53b44530518afbd85f8dc3b09e4196188a152ea117f22759c23ace31e
MD5 7f80801a86fe87a7961f73f59021e2f5
BLAKE2b-256 ca8fe248f7ad9c2efa7b11e9f0c1d945f13f66a56af1cbb1488725895b619706

See more details on using hashes here.

File details

Details for the file mctext-1.1.2-cp310-cp310-manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for mctext-1.1.2-cp310-cp310-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 fb354e01e4fc98d24b63a25a60c147d9cdc0363c27d380b1d0a8bd402802f5cd
MD5 80b56ada62289d296d8f2fcc4ee9dfb3
BLAKE2b-256 d6b1785c66a6f1aff072fd0db4be5fd9477d1a1a886b9dd576f916943731eded

See more details on using hashes here.

File details

Details for the file mctext-1.1.2-cp310-cp310-manylinux_2_24_aarch64.whl.

File metadata

File hashes

Hashes for mctext-1.1.2-cp310-cp310-manylinux_2_24_aarch64.whl
Algorithm Hash digest
SHA256 ee82b091c6a9ee474da6d9665379e797388c35e773f26a7d93f5ce3feb6ab8ce
MD5 c70c91103ba6a0dd7f2cf1722a77584f
BLAKE2b-256 9729219e350da9ffece26c83badd322d992502d7743755ce17c1876ece5a3ab6

See more details on using hashes here.

File details

Details for the file mctext-1.1.2-cp39-cp39-manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for mctext-1.1.2-cp39-cp39-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 47c5879132348d203c4d055c7c40059211999b63a1b5b3521d6a14f5083cff62
MD5 20ac7e6ae9ba5d1013c058b624a3412e
BLAKE2b-256 3be58b71472ba1e1b18f3d9f28db6e1f238043b3a28ee0f22cdebcb95ee6ecf1

See more details on using hashes here.

File details

Details for the file mctext-1.1.2-cp39-cp39-manylinux_2_24_aarch64.whl.

File metadata

File hashes

Hashes for mctext-1.1.2-cp39-cp39-manylinux_2_24_aarch64.whl
Algorithm Hash digest
SHA256 5ac4b4839b1130617f94525465688ea2c6e0b98a989b53afacc5a6a56e8dd2ae
MD5 23a772258d592e1325a94a3c50715b03
BLAKE2b-256 fa09dc8be80989a6da1a5f116b3cd8f11d5edd683a6fc498cba3ca437080c2f1

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