Skip to main content

A type-safe localization toolkit for parsing, converting, and matching TMX, XLIFF, PO, JSON, HTML, CSV, XLSX, and IDML files.

Project description

lokit

[!WARNING] Beta Release: lokit is currently in Beta. The API is volatile and subject to rapid, breaking changes prior to the official V1 release.


lokit is a high-performance, strictly type-safe, and highly memory-efficient localization toolkit for Python.


Supports Python 3.10+.




Unlike legacy tools that wrap around XML DOM element trees in-memory, lokit represents a shift away from XML-based localization interchange formats towards native language parsing. It ingests localization formats (TMX, XLIFF, PO, XLSX, CSV, JSON, HTML, IDML) and compiles them into a strict, unified structural data model. This enables not just parsing, but robust data manipulation, semantic extraction, and advanced translation memory features out-of-the-box. Lokit focuses on streaming and asynchronous processing rather than synchronous events using in-memory files.


This format type can be easily converted to JSON for interchange with other systems. I've made parsing and data transfers as native as possible by capturing all elements of traditional interchange formats in a common format structure. This allows for much better compatibility, especially in terms of segment matching and leveraging as it uses flattened strings as standard. Tags are preserved but as a common format, meaning the structure parsed from XLIFF will be the same as the structure parsed from HTML.


These legacy file formats have supported vendor-lock in for many year, making it difficult for any client to move to another system. Seeing that this is a major issue across the domain, something new is needed where vendors do not use hidden, legacy technology to lock in their clients. Localization deserves innovation.



The main premise here is a common, structured and type-safe dataclass model structure that is intentionally compatible with any file format, not just localization interchange formats, although these are optimized for performance and memory efficiency due to the verbose nature of XML based formats.


Note: This project was originally written in Rust and is still unreleased. Adding Rust extensions did not show a major performance improvement over the current C-Extension modules due to bridging overheads, this will be re-addressed in future releases. SDKs in other languages including the Rust prototype are coming soon.


Core Features


lokit provides a comprehensive suite of tools for managing localization data:

  • Native Structural Modeling: Converts interchange formats into a strict, unified Python Data classes, ensuring complete type safety.
  • Advanced Matching Engine: Provides Exact Matching, Fuzzy Matching (via SequenceMatcher), and In-Context Exact (ICE) Matching leveraging previous and next segment context, as well as with inline tags.
  • Sub-segment Extraction: Automatically parses and isolates inline tags, properties, and formatting markers, allowing for safe manipulation of text without corrupting code.
  • Semantic Querying: Easily filter translation units using any attribute, exact ID lookups, or deep nested JSON path querying (where()).
  • Plural Support: Native extraction and structuring of pluralized translation units, compatible with UI frameworks.
  • Universal Format Conversion: Instantly import and export between any supported format (e.g., TMX to JSON, HTML to XLIFF) with zero data loss.
  • Synchronous and Asynchronous Streaming: Process massive enterprise files natively using Python async generators to keep memory overhead to an absolute minimum.

Type Safety and C-Extensions


The entire library is very strictly typed and mypy compliant, so strict it compiles to C-extensions via mypyc and pre-attached via wheels. Additionally, any XML processing uses C-based packages. Compiling to these extensions has shown a 23% in overall performance increases over pure-python modules with additional benefits such as lower memory usage. C extensions are standard for MacOS (ARM+Intel), Windows, and Linux.


Parsing Performance


When dealing with enterprise-scale localization environments, parsing performance and memory efficiency are paramount. lokit is designed to be significantly leaner and faster than the industry standard.


Using another package, translate-toolkit, as a reference as it is the de-facto and feature-rich standard for localization file format parsing and conversion in Python for comparison, we benchmarked lokit's modules against its equivalents.


In a stress-test benchmark on a +600 MB .TMX file containing 557,058 segments, converting to JSON with Lokit.to_json_async() over 3 iterations yielded the following comparative averages:


Library Avg Duration Peak Memory Memory Efficiency
lokit 13.57s 135.9 MB 15x Less Memory
translate-toolkit 20.30s 2,034.5 MB ~2.0 GB

Tests for both covered from TMX to JSON with inline tag sanitization in both using the respective packages' tooling.


The major focus on memory safety allows for parallel processing of events, making it suitable for large-scale localization workflows and backend systems.


Note: this package is not a replacement or substitution for the already amazing translate-toolkit. The functionality is quite differet across both libraries and have their own use cases.



SDK Usage Reference


Lokit operates around a central BaseStructure dataclass model, which standardizes localization units and segments. This instructs better standardization and branching in a more language native way compared to XML based file formats. Parsing SDKs are added for both extraction and export tasks for localization interchange formats along with common file types.


Installation


Install lokit via pip:

pip install lokit-python

Basic Parsing and Conversion


Converting files synchronously is straightforward through the structured lokit API. Import the package once, then use the format paths under lokit.parsers and lokit.exporters.

import lokit

document = lokit.parsers.read.tmx("path/to/source.tmx")

lokit.exporters.write.xliff(document, "path/to/target.xliff")

Asynchronous Streaming for Large Interchange Files


For files spanning hundreds of megabytes, parsing the entire DOM structure into memory is inefficient. Lokit supports stream-parsing natively.


Here's some simple scripting code to show how easy it is. This simple program has no boilderplate and can be reduced to a few lines of code, but for the purpose of showcasing, we added some wrapper functions. The stream APIs take the static attributes such as language codes, keeping them in an immutable state. Then quickly streams the mutables. All other parsing modules also use streaming to parse to and from the common typed format.

import asyncio
import os

import lokit

input_dir = "data/language_tmx"
output_dir = "data/out"


async def convert_to_json(filepath: str):
    print(f"Starting: {filepath}")
    output = f"{output_dir}/{os.path.splitext(os.path.basename(filepath))[0]}.json"
    await lokit.parsers.stream.json(
        filepath=filepath,
        output=output,
    )
    print(f"Completed: {output}")


async def process():
    if not os.path.exists(output_dir):
        os.makedirs(output_dir, exist_ok=True)

    files = [os.path.join(input_dir, i) for i in os.listdir(input_dir)]
    tasks = [convert_to_json(filepath=file) for file in files]
    await asyncio.gather(*tasks)


if __name__ == "__main__":
    asyncio.run(process())

Advanced Querying and Matching


The Lokit logic wrapper provides access to the powerful matching engine and data manipulation features. This does not substitute for enterprise database semantic search but can be used as an after-step for evaluating matching results after retrieving translation units from a semantic/vector database.

import lokit

engine = lokit.Lokit.parse("path/to/source.xliff")

button_units = engine.where("extensions.component", "checkout_button")

results = engine.fuzzy_find("Complete your purchase", limit=5, threshold=0.75)
for match in results:
    print(f"Match found: {match.unit_id} (Score: {match.score})")

ice_match = engine.match(
    source="Submit",
    target_unit_id="submit_btn_1",
    previous_source="Enter your email",
    require_context=True
)

Structured API Paths

The preferred public API is available from a single package import:

import lokit

document = lokit.parsers.read.file("path/to/source.tmx")
document = lokit.parsers.read.csv("path/to/source.csv", source_locale="en-US")
streamed_tmx = lokit.parsers.stream.tmx("path/to/source.tmx")


async def stream_to_json() -> None:
    await lokit.parsers.stream.json("path/to/source.tmx", "path/to/out")

lokit.exporters.write.csv(document, "path/to/target.csv")


async def export_xlsx() -> None:
    await lokit.exporters.async_.xlsx(document, "path/to/target.xlsx")

CsvExtractor = lokit.parsers.extractors.csv

Existing direct imports from lokit.importers, lokit.exporters, and format modules remain supported for compatibility.



Supported Formats


  • TMX
  • XLIFF
  • PO/POT
  • XLSX
  • CSV
  • JSON
  • HTML
  • IDML

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

lokit_python-0.1.4.tar.gz (61.9 kB view details)

Uploaded Source

Built Distributions

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

lokit_python-0.1.4-cp313-cp313-win_amd64.whl (929.3 kB view details)

Uploaded CPython 3.13Windows x86-64

lokit_python-0.1.4-cp313-cp313-win32.whl (798.1 kB view details)

Uploaded CPython 3.13Windows x86

lokit_python-0.1.4-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

lokit_python-0.1.4-cp313-cp313-macosx_11_0_arm64.whl (837.8 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

lokit_python-0.1.4-cp313-cp313-macosx_10_13_x86_64.whl (900.4 kB view details)

Uploaded CPython 3.13macOS 10.13+ x86-64

lokit_python-0.1.4-cp312-cp312-win_amd64.whl (928.0 kB view details)

Uploaded CPython 3.12Windows x86-64

lokit_python-0.1.4-cp312-cp312-win32.whl (798.4 kB view details)

Uploaded CPython 3.12Windows x86

lokit_python-0.1.4-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

lokit_python-0.1.4-cp312-cp312-macosx_11_0_arm64.whl (838.9 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

lokit_python-0.1.4-cp312-cp312-macosx_10_13_x86_64.whl (902.7 kB view details)

Uploaded CPython 3.12macOS 10.13+ x86-64

File details

Details for the file lokit_python-0.1.4.tar.gz.

File metadata

  • Download URL: lokit_python-0.1.4.tar.gz
  • Upload date:
  • Size: 61.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for lokit_python-0.1.4.tar.gz
Algorithm Hash digest
SHA256 c4c61368617f12e0237530e2d65693becb8410d15f0b8f958ef514a394242447
MD5 c809eeb1896f56c7ceb86c07d8d9962e
BLAKE2b-256 ee25071a6ed71190c6da39738f4fb9ec8615ccb525c579f1dab3159599f817b0

See more details on using hashes here.

Provenance

The following attestation bundles were made for lokit_python-0.1.4.tar.gz:

Publisher: publish.yml on ciarandarby/lokit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lokit_python-0.1.4-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for lokit_python-0.1.4-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 064f0d6c0fc9ba91f69878d494f87e5eca076cbbdb865ebab4a3e34aec954476
MD5 c6e41ec53810a1e8f1d234716f88a927
BLAKE2b-256 91d9aa1d2eb1ea85f988ff60548eb73b385f7ed04fe5ce9817f619a9d2e66fe0

See more details on using hashes here.

Provenance

The following attestation bundles were made for lokit_python-0.1.4-cp313-cp313-win_amd64.whl:

Publisher: publish.yml on ciarandarby/lokit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lokit_python-0.1.4-cp313-cp313-win32.whl.

File metadata

  • Download URL: lokit_python-0.1.4-cp313-cp313-win32.whl
  • Upload date:
  • Size: 798.1 kB
  • Tags: CPython 3.13, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for lokit_python-0.1.4-cp313-cp313-win32.whl
Algorithm Hash digest
SHA256 7fafec8d20ceccc6be250c42534e661947edeb813e6363274fcc92a27f24415e
MD5 e31efcbf2f393f28a2ac1affcab54c70
BLAKE2b-256 383bef68642dd74fe042b82d6be40f8d515513926c5fadd2313bd4ff95af0a95

See more details on using hashes here.

Provenance

The following attestation bundles were made for lokit_python-0.1.4-cp313-cp313-win32.whl:

Publisher: publish.yml on ciarandarby/lokit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lokit_python-0.1.4-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for lokit_python-0.1.4-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 64b60b6e245ec29894184f3abadcb8e5cadbc8002abf26acd89132c5f0531ba8
MD5 ee23625811edb3f79488eaf617c5af28
BLAKE2b-256 0de407664e662b59fceeeb93aaf9b31a2a1112537a288e885d80fb087b0b5e15

See more details on using hashes here.

Provenance

The following attestation bundles were made for lokit_python-0.1.4-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: publish.yml on ciarandarby/lokit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lokit_python-0.1.4-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for lokit_python-0.1.4-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5e43e43f8de252b35d73cbfd0ac557ed4114de249f391bb555acb6e388e1a529
MD5 daf0b1ed261ec9450bb074ad92b0f9f7
BLAKE2b-256 ab03808805710dda4f02962ce704c457d2d6d85688109e2c8634c6b4420722be

See more details on using hashes here.

Provenance

The following attestation bundles were made for lokit_python-0.1.4-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: publish.yml on ciarandarby/lokit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lokit_python-0.1.4-cp313-cp313-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for lokit_python-0.1.4-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 dd9bfe5b4b7f3aed496b2727a2c51f087f658725f996270b7cf24779d192b76f
MD5 836dc4444d50ab10f409e26f258438d2
BLAKE2b-256 af45859bb63a1246fd7c92855d069e32cb04ec4d70b3681381d7cef3c0641fd4

See more details on using hashes here.

Provenance

The following attestation bundles were made for lokit_python-0.1.4-cp313-cp313-macosx_10_13_x86_64.whl:

Publisher: publish.yml on ciarandarby/lokit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lokit_python-0.1.4-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for lokit_python-0.1.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 758e94ac05593c65b01b29b5657da742c009bd4176b3712ae65060351bd254e6
MD5 9aac1023d0ee2d8a3d7d63a85aff7297
BLAKE2b-256 c2ff604a8e5be5e9197d3d4bae032f32a73ed178e8087d6d578abc011c138d0a

See more details on using hashes here.

Provenance

The following attestation bundles were made for lokit_python-0.1.4-cp312-cp312-win_amd64.whl:

Publisher: publish.yml on ciarandarby/lokit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lokit_python-0.1.4-cp312-cp312-win32.whl.

File metadata

  • Download URL: lokit_python-0.1.4-cp312-cp312-win32.whl
  • Upload date:
  • Size: 798.4 kB
  • Tags: CPython 3.12, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for lokit_python-0.1.4-cp312-cp312-win32.whl
Algorithm Hash digest
SHA256 60181a85706c8e6fb1e4934ceb3b4d8d8bc5a05884d68831cfe2aa410f38bba8
MD5 715535592122a46e0db7f45b7857280c
BLAKE2b-256 42c32cf13d6dc2dda0455433dcfaf9b6b61d253f761ceab78ac7a4ebae0615b2

See more details on using hashes here.

Provenance

The following attestation bundles were made for lokit_python-0.1.4-cp312-cp312-win32.whl:

Publisher: publish.yml on ciarandarby/lokit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lokit_python-0.1.4-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for lokit_python-0.1.4-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9687ea6aaf03a30d010dfd59160dd9c6bc947ba99881f481642b1a05923f5130
MD5 cbe21e5959ccc0ef4e648435c53449c8
BLAKE2b-256 7fde045b2bca7809f96de0f9194430695e0caa987cf1808db416e9c8a07f9656

See more details on using hashes here.

Provenance

The following attestation bundles were made for lokit_python-0.1.4-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: publish.yml on ciarandarby/lokit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lokit_python-0.1.4-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for lokit_python-0.1.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a0fbf058ac6e4d19779e1fa5a9255efd6f86fcbb6259a79555e2240292132b80
MD5 047a0402e0c910bc3023b062dc1de784
BLAKE2b-256 e934707dbf25a5a67875df7ca1a5073e55cb592bbefe338db750273138c87dac

See more details on using hashes here.

Provenance

The following attestation bundles were made for lokit_python-0.1.4-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: publish.yml on ciarandarby/lokit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lokit_python-0.1.4-cp312-cp312-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for lokit_python-0.1.4-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 6c23d87b33188d73b894d2f94a96db63a5f39ff430f7ca4192d5ff2e46116a75
MD5 03e89d15d98dfc0c1497f87411ad04b2
BLAKE2b-256 f45d4318dc1746f09ecac7c9ec65ca7ba2620d2ee136843e6aa7dc3ae445e954

See more details on using hashes here.

Provenance

The following attestation bundles were made for lokit_python-0.1.4-cp312-cp312-macosx_10_13_x86_64.whl:

Publisher: publish.yml on ciarandarby/lokit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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