Skip to main content

MessageFormat2 Documentation Status CI

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

Documentation is available here: https://messageformat2.readthedocs.io/en/latest/

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 ("""\
.input {$count :number}
.match $count
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 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for messageformat2 1.0.0
File Size Uploaded Provenance Actions
messageformat2-1.0.0.tar.gz 105.2 kB With provenance Details for messageformat2-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for messageformat2 1.0.0
File Interpreter ABI Platform Actions
messageformat2-1.0.0-py3-none-any.whl Python 3 none any Details for messageformat2-1.0.0-py3-none-any.whl

Total release size: 130.7 kB

Release files / messageformat2-1.0.0.tar.gz

Download URL messageformat2-1.0.0.tar.gz
Size 105.2 kB
Tags Source
SHA-256 checksum
How to use checksums
8f525201b8a43befdbf17774051e9e7bbecfdfaee4d5526bd94c2bd6197c96bc
BLAKE2b-256 checksum
How to use checksums
9f6a2d5f47ee7ca1349baa7a51248db1847d24a8980d9f979c07eecc554cc7fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 4, 2026.

Transparency log

Release files / messageformat2-1.0.0-py3-none-any.whl

Download URL messageformat2-1.0.0-py3-none-any.whl
Size 25.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9d3777f257998cd0437b28de57e8be60213375facc8938ee07c6faecb5a13d49
BLAKE2b-256 checksum
How to use checksums
035b75c863d0a04207a44b6131bacf48ebdf0a43f6573fdd9f2f36f1fdb8d364
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 4, 2026.

Transparency log

Security for messageformat2 1.0.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for messageformat2-1.0.0.tar.gz

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 Nov 4, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page