Skip to main content

Python library for manipulating, creating and editing tmx files

Project description

Hypomnema

PyPI version License: MIT Python 3.13+

The industrial-grade TMX framework for Python.

Hypomnema is a low-level, strictly typed infrastructure library for working with TMX 1.4b (Translation Memory eXchange) files in Python.

It is designed as a foundation for building localization, CAT, and NLP tooling — not as an end-user convenience API.
Version 0.4.x intentionally exposes only the core primitives and orchestration layers.

⚠️ Hypomnema is still in active development. Expect breaking changes without notice.

🚀 Why this library?

Most TMX parsers are simple XML wrappers. Hypomnema is an infrastructure library offering:

  • 🛡️ Policy-Driven Recovery: Configure exactly how to handle errors (missing segments, extra text, invalid tags)
  • 🔌 Backend Agnostic: Runs on lxml for speed or standard xml.etree for zero-dependency environments, or even build your own.
  • ✨ Type Safe: Fully annotated with modern Python 3.13+ types. Returns structured Dataclasses, not raw XML nodes.
  • 🏗️ Symmetrical: Deserialize XML to Objects, manipulate them, and Serialize back to XML with roundtrip integrity.

📦 Installation

pip install hypomnema
OR
uv add hypomnema

For maximum performance, install with lxml support and use the LxmlBackend:

pip install "hypomnema[lxml]"
OR
uv add hypomnema[lxml]

⚡ Usage (Low-Level API)

Note: v0.4.x exposes the core architecture components. Better docs and high-level convenience facades are coming in v0.5.

import hypomnema as hm

# Initialize the Deserializer with a backend
deserializer = hm.Deserializer(backend=hm.StandardBackend())

# Parse the file using the backend and let the deserializer do the work for you
tmx_object = deserializer.deserialize(deserializer.backend.parse("memory.tmx"))

# Inspect and manipulate the object however you want
assert isinstance(tmx_object, hm.Tmx)
print(f"Source Language: {tmx_object.header.srclang}")
print(f"Number of TUs: {len(tmx_object.body)}")
for tu in tmx_object.body:
  if tu.creationdate is None or tu.creationdate.year < 2020:
    del tu

# Initialize the Serializer with a backend (doesn't need to be the same as the Deserializer!)
serializer = hm.Serializer(backend=hm.LxmlBackend())

# Serialize the object back to XML
xml_root = serializer.serialize(tmx_object)

# Write the XML to a file
serializer.backend.write(xml_root, "output.tmx")

Handling Dirty Data (Policies)

Real-world TMX files are often broken. Configure a DeserializationPolicy to handle errors when parsing a tmx file and a SerializationPolicy to handle errors when serializing back to XML.

By default, hypomnema is configured to fail fast and prevent silent data corruption.

You can also configure the logging level for each policy value independently of its behavior and even pass your own logger instance to every object irrespective of its policy to control logging.

🧩 Architecture

The library is built on three decoupled layers:

  1. Backend Layer: Abstracts the XML parser. LxmlBackend (fast, features) vs StandardBackend (portable). You can also build your own by subclassing XmlBackend and implementing the required methods.
  2. Orchestration Layer: Serializer and Deserializer classes that manage recursion and dispatch to the correct handler.
  3. Handler Layer: Specialized classes (TuvDeserializer, NoteSerializer) that implement the business logic and policy checks for specific TMX elements.

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

hypomnema-0.4.4.tar.gz (26.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hypomnema-0.4.4-py3-none-any.whl (33.1 kB view details)

Uploaded Python 3

File details

Details for the file hypomnema-0.4.4.tar.gz.

File metadata

  • Download URL: hypomnema-0.4.4.tar.gz
  • Upload date:
  • Size: 26.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for hypomnema-0.4.4.tar.gz
Algorithm Hash digest
SHA256 af577addc65c980bac70016300dbd575a89f28bff89d0d89e4e80936a5d2dfab
MD5 db3d37f5d015096efcc28a7a86bba5cd
BLAKE2b-256 7a930faa22fd16285047ce251a22fd209a6345615077d4c061a31aa55ec39156

See more details on using hashes here.

File details

Details for the file hypomnema-0.4.4-py3-none-any.whl.

File metadata

  • Download URL: hypomnema-0.4.4-py3-none-any.whl
  • Upload date:
  • Size: 33.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for hypomnema-0.4.4-py3-none-any.whl
Algorithm Hash digest
SHA256 153e176f0c52cff2efe9384fba2deae90fe50b20ad31ba5b72171b1d0b3a8d5c
MD5 0fa298b4cf3a8fa4b6e61030fcfd1254
BLAKE2b-256 92d5684f5255e127643b6af7d065e53b529e8f182fa31bef5a8dff847b1e101d

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