MessageFormat2

This is a Python implementation of the Unicode Message Format 2.0 specification.
Message Format 2.0 (MF2) is a new iteration of Message Format which aims to be more expressive and flexible than both Message Format 1.0 and, in the context of Python, gettext.
If you would like to learn more about MF2 itself head over to the Unicode technical specification.
Features
The library includes:
- A message parser and a formatter
- Several builtin formatters and selectors described by the spec and the possibility to write custom formatters/selectors
- Helper classes to inspect and transform the message data model
Documentation
Installation
Via pip for Python >= 3.12
pip install messageformat2
Examples
Simple messages
from messageformat2 import format_message
format_message("Hello, {$name}!", {"name": "Alice"}) # -> "Hello, Alice!"
Messages can be reused with different inputs.
from messageformat2 import Message
message = Message("Hello, {$name}!")
message.format({"name": "Alice"}) # -> "Hello, Alice!"
message.format({"name": "Bob"}) # -> "Hello, Bob!"
Built-in formatters
There are several builtin locale-aware formatters available.
from datetime import datetime
from messageformat2 import Message
message = Message("Today's date is {$now :date}")
now = datetime.now()
message.format({"now": now}, locale='en_US')
# -> Today's date is 5/10/2024
message.format({"now": now}, locale='en_GB')
# -> Today's date is 10/05/2024
Plural support
MF2 supports pluralization using built-in or custom selectors.
from messageformat2 import Message
msg = Message ("""\
.match {$count :number}
one {{You have {$count} notification.}}
* {{You have {$count} notifications.}}
""")
msg.format({"count": 42}, locale='en_US') # -> "You have 42 notifications."
msg.format({"count": 1}, locale='en_US') # -> "You have 1 notification."
Complete documentation is available here.
Metadata
Release files for messageformat2 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| messageformat2-0.1.1.tar.gz | 62.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| messageformat2-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 80.8 kB
Release files / messageformat2-0.1.1.tar.gz
| Download URL | messageformat2-0.1.1.tar.gz |
|---|---|
| Size | 62.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
531e34d9133477673a5416372e9b0f95d77066bf0ea2eb74ae760488fb8188e9
|
|
BLAKE2b-256 checksum How to use checksums |
bb38035a3be3df2c8edda4ec2b03384cd9c832afe2612ed088dce569659bcdd4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 3, 2025.
Transparency logRelease files / messageformat2-0.1.1-py3-none-any.whl
| Download URL | messageformat2-0.1.1-py3-none-any.whl |
|---|---|
| Size | 18.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5fd88485fc2fee071a64e25d0759a036faa6a87df8540ff91f7d60dadfae5acf
|
|
BLAKE2b-256 checksum How to use checksums |
10161c4262cdbd85c0f71db6a527f85a2245ef5222d31a98ee09ac680bd97813
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 3, 2025.
Transparency log