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().add("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
add(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().add("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.0.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.0-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.0-cp313-cp313-manylinux_2_24_aarch64.whl (12.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.24+ ARM64

mctext-1.1.0-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.0-cp312-cp312-manylinux_2_24_aarch64.whl (12.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.24+ ARM64

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

Uploaded CPython 3.11Windows x86-64

mctext-1.1.0-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.0-cp311-cp311-manylinux_2_24_aarch64.whl (12.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.24+ ARM64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 10.12+ x86-64

mctext-1.1.0-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.0-cp310-cp310-manylinux_2_24_aarch64.whl (12.5 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.24+ ARM64

mctext-1.1.0-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.0-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.0.tar.gz.

File metadata

  • Download URL: mctext-1.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 11e973317ad1a6ac8687b42a1a25192f390772eddba63df49ddd6bce87579ece
MD5 c8bef968827c0fea3adc5cf2977c9550
BLAKE2b-256 02782913a271f0590690c8cf25e613b9825c3da3d3e61b64734743074936b09d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mctext-1.1.0-cp313-cp313-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 17d6d9fc2925aaef2515f8a0324f8934aa611dcc7d86bd957471ea0fdf58ad56
MD5 06e79744825cb380493d212472055a73
BLAKE2b-256 08a9ae68ae6442b8d74d994dbf9c818ab203a661d39fde7d35310b2d855fdd8f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mctext-1.1.0-cp313-cp313-manylinux_2_24_aarch64.whl
Algorithm Hash digest
SHA256 78c1630e1d1037064b704747bfa6db7419c60941d3e3bb1f587db2e2d2d51ced
MD5 3d098108c34e48ae22f5b36a33c90046
BLAKE2b-256 178455586e4ee4080ce7a9d6e82a7e7c5d5dcc3773db1a710152027c67625571

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mctext-1.1.0-cp312-cp312-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 7deda06136bc742471ac017d8d1cd31a7de5b939b84b3027e6480f24386b68e3
MD5 25077ee8ea0bbe6bfff6485ec38f7cad
BLAKE2b-256 717be325921a5910be4b3ada39b836bdffec67eefa893ee0700b6a11f3815650

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mctext-1.1.0-cp312-cp312-manylinux_2_24_aarch64.whl
Algorithm Hash digest
SHA256 5cc8a6c315311f9e63f6cc9dec6f642d7882f93876886b282daecb91d7646276
MD5 16b50396e00d36ba6d1fd57043122219
BLAKE2b-256 ac3a23e5f7f8ded52690d8d05afd1ed2fe880ed38c7364c703840f69d3ad0f87

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for mctext-1.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 08600468a3d4dc99cd4aed679f542d5a6484c0e08d4a180a752cb0440bfa29b9
MD5 2eb479a0775e6b74cba5053ca8e2de51
BLAKE2b-256 fa19edbefb1fb81b7e733e5a13f3d97db4a360138ddeeb85280273c4debd6065

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mctext-1.1.0-cp311-cp311-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 68ff2dc7f1f0aae3b9080ff025e09a5b3dce312cea0aba9ab213bae9d499e402
MD5 c6300c386f68606ad6760723e6f475d4
BLAKE2b-256 c050cc125f20f9b16e8cf2e9fea30245991c9d868d8c92fb638673b042336aa4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mctext-1.1.0-cp311-cp311-manylinux_2_24_aarch64.whl
Algorithm Hash digest
SHA256 b7a574a3b2821f06e39e1c0e5d73471d9e82d7679ec2e718374c1727b6a8ebbe
MD5 d23de5e66623fb77d559b4667753d77b
BLAKE2b-256 e03b050922c6463b48c4903f40ca5120640061f945f4a893fd64206863ca2b0f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mctext-1.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8eee8bebb33ddc961c1c261ab8e5b36057cf8b26db6a69998376734dcd297fe4
MD5 9bb35edc77f6513957dc07f22a53d93d
BLAKE2b-256 e34b425e113051731e1b37f9c70f9d5a3e0a0a322f20cacf549be2c58d1f703d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mctext-1.1.0-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 06e8f24ef8c59d7e6a58c2ea9d673e4e4e007cc338fd9b404f21cf28df12898f
MD5 f7321ca6ca9e9ce00d3876b4dbe0ddd9
BLAKE2b-256 696e78642e3b5361bdccf2071a08827723422b9b70e0fbe45ebf1c0e4bd8c611

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mctext-1.1.0-cp310-cp310-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 b07cea332f7a34be4e80af7e955a778749e8c92cf286457f2d9ccede26705321
MD5 4b6a04f222b41f25de6b05d6b2ca603e
BLAKE2b-256 5e062fa269ede6dbf8de1b5509e2b2f4ae89cc6fe50b2197822a0f448b1ca60a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mctext-1.1.0-cp310-cp310-manylinux_2_24_aarch64.whl
Algorithm Hash digest
SHA256 e4dccfe0a80a455533d0717012ef4b33d4a2b7298bab78d0e1882be42a275299
MD5 4bc981b2e3db9dafec078ec133918a9d
BLAKE2b-256 2afde7c569af72d7cba7b58d0cbdab64052818036254098cd3fad2849c4f3fed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mctext-1.1.0-cp39-cp39-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 5d1c551e0e6962f64d512a572c5c3e15d4994e29eff096ecbd794d15dad55115
MD5 2109483489516915229d2fab1b198f8a
BLAKE2b-256 54aeb8334670bf502e966bebe9e34f76dea760dfa55887af611bebaed0de54cc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mctext-1.1.0-cp39-cp39-manylinux_2_24_aarch64.whl
Algorithm Hash digest
SHA256 d86eb39d4e6d9395c32b231e04660bda288b6020e7711116875efa8aa38d4414
MD5 2f86dd4bcdd452b8e6639e6c329d58a8
BLAKE2b-256 ccd35d83946bbd47780c2427a91cde2c43ea6ac2325218641767d613fb51f95c

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