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

Uploaded CPython 3.13manylinux: glibc 2.24+ ARM64

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

Uploaded CPython 3.12manylinux: glibc 2.24+ ARM64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11manylinux: glibc 2.24+ ARM64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 10.12+ x86-64

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

Uploaded CPython 3.10manylinux: glibc 2.24+ ARM64

mctext-1.1.1-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.1-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.1.tar.gz.

File metadata

  • Download URL: mctext-1.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 120f00f40c6bf8512ef9d20a88cc78937485f36aefc5feba3dc8b705847fafff
MD5 b3a2695e1170e9ee223df612ab131552
BLAKE2b-256 2278ea69f11c3e4228039ba15e1c62e7f963176813f4ba320d126cf5f2a9d273

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mctext-1.1.1-cp313-cp313-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 4524d28081fe15a309cdcb7b3ff166413c1188db55b3c45e3577ded5fb550506
MD5 f685f606bfbcad77adc96ed9e76c3457
BLAKE2b-256 899caf168832b87edb3b87cb04cd62fb7d08ab5a674ec5d10d7ca84cca28d520

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mctext-1.1.1-cp313-cp313-manylinux_2_24_aarch64.whl
Algorithm Hash digest
SHA256 c2ba0bd7ca525fa0ba68b45a2eb8ff84be6ddc34bfcd0526ca4333f10778456b
MD5 c812a3d87885a6c202ad21115ab9b8fd
BLAKE2b-256 e4d611c90df8cfdc6b064c29f45708f3b047ae43adaa326131477f87e25002a2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mctext-1.1.1-cp312-cp312-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 1f4229960ac631859f074f47d0fea52f9437c2c85ff5880f3d43833c4f2dced0
MD5 077f2fd7dede05b7c13f89b3f22b3e3b
BLAKE2b-256 4146f220bec7f84d308ec260202e681e1d119bbf814d8c2b60758a91d5dba5d6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mctext-1.1.1-cp312-cp312-manylinux_2_24_aarch64.whl
Algorithm Hash digest
SHA256 c4585eed6d20c86152eaf93c76af0d217bc52d2fe56af0858d222844a8ee9ea8
MD5 9a041835fc8f61eaa05d95548c8de58c
BLAKE2b-256 2b64424b66acfe3d732d3927a694f2840d03657bd66a598306d19bb50dd05483

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mctext-1.1.1-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.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 c83e36f4397acdfa788fb419e7333c29b1706a68a65c6a05d331944b89a55120
MD5 bdc6d3a0dba34f62c66ad2db4703383e
BLAKE2b-256 90382ec999b619686b3b61176a87408fcdb0cf9efdb2b837d47b9fd9d1da432f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mctext-1.1.1-cp311-cp311-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 3cfae90aedd420d163353721ce9efa8b29ebaf1757bd465f7b6bc33d02686815
MD5 7491b9e57bfd870aaf05b72f30f87699
BLAKE2b-256 cff3a3917e4d2f8c7fea52f06e3b1aacc772034248d10121013691feeb0647a3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mctext-1.1.1-cp311-cp311-manylinux_2_24_aarch64.whl
Algorithm Hash digest
SHA256 0b76b54a0dff89fc53ee12996a2bcaf0f324c2633dce92845babcc6a5fec8106
MD5 eb558a9f109db3d7125a294f74b29f7a
BLAKE2b-256 53d380419e125cd96ad87dd689fad9446db9662c8fc381954b75272c592dcc86

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mctext-1.1.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3fc47360d94fa269a33ce66e720f6d87508522bcc6088efe96017d1e457516c9
MD5 0d33d4ca86f5b4a97102a49f629c6d61
BLAKE2b-256 0192b80fb9d5a4d1ab1caa577be35313c15affdda91b933e65db0eee440302a9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mctext-1.1.1-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ae5961dd0b63587b469a627c9860e50f667ebb0117a8e50679d964a8d5496c3b
MD5 cd8752597ea750a32324a4fe7ba6338a
BLAKE2b-256 2826027798e811e6c905d05c7f0fd331a9bd6c704d607dab8f3b07fef77c15dc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mctext-1.1.1-cp310-cp310-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 541e147eb55964f540f6bcc880385282a755e668e79c62f0261c8557b0051c46
MD5 6bf6c7b346a6ba0d6be121fe7f14dd99
BLAKE2b-256 092bf6c8f24967bdee492badb592f7895e940691ead9f17c4d766ab7fc4adf0e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mctext-1.1.1-cp310-cp310-manylinux_2_24_aarch64.whl
Algorithm Hash digest
SHA256 bc15791f2dcf861ee3412bbcb6224cca166dd9e0ec23f57c9950a6c57bf3c7ba
MD5 e646cf8e99a69961f6bf4a4121c0bcea
BLAKE2b-256 8e6d47f3f8697eaf7f8bb5093e991616f8980b7e16f6d66c09bb5e5ec1c82ef1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mctext-1.1.1-cp39-cp39-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 f2a2948f5cd3e8ba4149cbbaeac8fb38f942a6f8f13b7b085ff0a5bb47c44f46
MD5 a6b9a3b9dce0898aba4cffd5f772de1f
BLAKE2b-256 d54864363aef44590a517964449f38d531b7111a063886789b3869ac75bdd255

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mctext-1.1.1-cp39-cp39-manylinux_2_24_aarch64.whl
Algorithm Hash digest
SHA256 eb99dbf519f2e163e43f7c4c5d61e55126a5aad10cf1bb390b85f891fccfc179
MD5 7558e5254ca1275202d42a93eb7f3cec
BLAKE2b-256 d01bc11e82e066d68aa8fb039d5f137c0e568cc8be501077a107fa158ff7bdcb

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