Skip to main content

Python localization toolkit for parsing, converting, and matching TMX, XLIFF, PO, JSON, HTML, CSV, XLSX, and IDML. Includes direct translation memory database ingestion.

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. Lokit is the first open source package that supports direct localization interchange to database ingestion; even outside the Python ecosystem.



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.


PostgreSQL API

Install the optional database extra to use PostgreSQL-backed translation memory:

pip install "lokit-python[db]"
import lokit


async def load_and_match() -> None:
    tm = await lokit.db.connect("postgresql://localhost/lokit_tm")
    async with tm:
        await tm.setup()

        stream = lokit.parsers.stream.tmx("translation_memory.tmx")
        await tm.load(stream)

        results = await tm.match(
            source="Roses are red",
            source_locale="en-US",
            target_locale="fr-FR",
            limit=5,
            threshold=0.5,
        )
        print(results[0].unit_id, results[0].kind, results[0].score)

The database stores plain source and target text in PostgreSQL, uses pg_trgm for exact/fuzzy lookup, and reconstructs lokit Data objects with tags, comments and metadata along with adjecent context. This allows for plan string matching with tag and metadata propagation.


Enterprise Database Support

With the above local database ingestion and runtime logic, Lokit has direct connection APIs to external enterprise services. Currently supporting AWS (RDS & Aurora), GCP (Cloud SQL & AlloyDB) along with serverless platforms Supabase and Neon. Pipeline is support and enabled by default but configurable. Dual read and write URIs are also accepted for maximum performance while a single URI can still be used for simplicity or where it is not supported in the service used.

The API includes a full backend framework for handling localization database operations including matching, tag, pluralization and properity propigation, read and writes, and concurrent data handeling to and from the database server. All in async and with concurrency where supported by the service.

Lokit can handle direct streaming from legacy interchange formats to enterprise databses with complete customization, no hidden dependencies, no boilerplate and highly optimized data flows.

Lokit is the first ever package to support this in any language ecosystem.

pip install "lokit-python[db-aws]"
pip install "lokit-python[db-gcp]"
import lokit

tm_rds = await lokit.db.connect(
    "postgresql://user:pass@instance.rds.amazonaws.com:5432/tm?sslmode=require"
)

tm_aurora = await lokit.db.connect(
    "postgresql://user:pass@cluster.rds.amazonaws.com:5432/tm?sslmode=require",
    reader_uri="postgresql://user:pass@cluster-ro.rds.amazonaws.com:5432/tm?sslmode=require"
)

tm_gcp = await lokit.db.connect(
    "postgresql://user:pass@/tm?host=/cloudsql/project:region:instance"
)

tm_supabase = await lokit.db.connect(
    "postgresql://postgres.project-ref:pass@aws-0-region.pooler.supabase.com:6543/postgres?sslmode=require",
    pipeline=False
)

tm_neon = await lokit.db.connect(
    "postgresql://user:pass@ep-cool-darkness-123456.us-east-2.aws.neon.tech/tm?sslmode=require",
    pipeline=False
)


Supported Formats for Parsing


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


Learn More

Visit the official homepage at lokit.org, more detailed documentation is to come before the V1 release.

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.2.0.tar.gz (81.5 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.2.0-cp313-cp313-win_amd64.whl (1.0 MB view details)

Uploaded CPython 3.13Windows x86-64

lokit_python-0.2.0-cp313-cp313-win32.whl (893.0 kB view details)

Uploaded CPython 3.13Windows x86

lokit_python-0.2.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.2 MB view details)

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

lokit_python-0.2.0-cp313-cp313-macosx_11_0_arm64.whl (934.6 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

lokit_python-0.2.0-cp313-cp313-macosx_10_13_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.13macOS 10.13+ x86-64

lokit_python-0.2.0-cp312-cp312-win_amd64.whl (1.0 MB view details)

Uploaded CPython 3.12Windows x86-64

lokit_python-0.2.0-cp312-cp312-win32.whl (892.9 kB view details)

Uploaded CPython 3.12Windows x86

lokit_python-0.2.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.2 MB view details)

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

lokit_python-0.2.0-cp312-cp312-macosx_11_0_arm64.whl (936.9 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

lokit_python-0.2.0-cp312-cp312-macosx_10_13_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.12macOS 10.13+ x86-64

File details

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

File metadata

  • Download URL: lokit_python-0.2.0.tar.gz
  • Upload date:
  • Size: 81.5 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.2.0.tar.gz
Algorithm Hash digest
SHA256 5ea2ad122bf45a0ba018c55cc9865b06a06fbf4aefee121bd41f8a62be5763a1
MD5 8e1232e2c1b57de831f9d183adefed07
BLAKE2b-256 81d9afd20fa0ce7cef596936a4135648ce3f96ac68ccad296e7fe166235a80e6

See more details on using hashes here.

Provenance

The following attestation bundles were made for lokit_python-0.2.0.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.2.0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for lokit_python-0.2.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 5a90da8a9ceebe62b742926ec22c2a3ba216214be49f88049b03e10c7e2db643
MD5 58e6de249000866fcba39db8888dcf9d
BLAKE2b-256 04ad55df87938f32c945dc3b6aa5a4daac1118521bd3f3f2b230e4ea91037fc0

See more details on using hashes here.

Provenance

The following attestation bundles were made for lokit_python-0.2.0-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.2.0-cp313-cp313-win32.whl.

File metadata

  • Download URL: lokit_python-0.2.0-cp313-cp313-win32.whl
  • Upload date:
  • Size: 893.0 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.2.0-cp313-cp313-win32.whl
Algorithm Hash digest
SHA256 22de2b0d6af39279d436cacfd3d2bcbbda99ff310159842caa03ddeef1f12149
MD5 1cdce766dba7baabeb8abe680e96e622
BLAKE2b-256 80b74b5dee5f55b8f3d2ebb018c64ff647d9e167ac5d87a4b30ecd63a0a6e66e

See more details on using hashes here.

Provenance

The following attestation bundles were made for lokit_python-0.2.0-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.2.0-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.2.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 456307d143d51e6cf898bf87383f38ea55d17e717ddaf9fb1a86d1e35e42b9c8
MD5 6bbe95d424d83a4db8d4c3a5be8c4e12
BLAKE2b-256 0088ff28d5874a2a01142eeaf707a0f8d85f6dd4fb946862386504c133f070e3

See more details on using hashes here.

Provenance

The following attestation bundles were made for lokit_python-0.2.0-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.2.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for lokit_python-0.2.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c60382f894c4f028c9284cc5720ca21c2a0b81368e63c9479c4af974a41a8f78
MD5 2d4ec26a059e0a35fb002add1b0bc705
BLAKE2b-256 ab9f1b20393d28cbcd0e8799c3ff2e304c082d1a4e5c9c6f947046d7522d1217

See more details on using hashes here.

Provenance

The following attestation bundles were made for lokit_python-0.2.0-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.2.0-cp313-cp313-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for lokit_python-0.2.0-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 54165b02ea751d40e1246e25b33904aac660783025374152c16629bb9e45477d
MD5 cc456b8de1f541e121acd302a37da38d
BLAKE2b-256 55e22118654f6c6824a767f1116d70d6b66ba06d0872c403c1203e4f23c84aed

See more details on using hashes here.

Provenance

The following attestation bundles were made for lokit_python-0.2.0-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.2.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for lokit_python-0.2.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 15c545481b07d390c7991c569f736c9c28f2815347ec607d0cc73b8294caf40c
MD5 373343dc1c9ad9b9651c2cd68828031f
BLAKE2b-256 dd44b462c338b4b95cd8b584926ac588a97bcbbcec3fbdbee3b411a2433411d4

See more details on using hashes here.

Provenance

The following attestation bundles were made for lokit_python-0.2.0-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.2.0-cp312-cp312-win32.whl.

File metadata

  • Download URL: lokit_python-0.2.0-cp312-cp312-win32.whl
  • Upload date:
  • Size: 892.9 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.2.0-cp312-cp312-win32.whl
Algorithm Hash digest
SHA256 f40e7565ed73af3e23f2fc25f03b9bbb86f4e4b4e82e36195a0bd1c70509d422
MD5 76ef6c8d8176beca1e49647ddcd0a58d
BLAKE2b-256 c82f34537f3b8a62348f398b85fd3a53d0b1b58be17c1b8d8a54779ccbd50ff4

See more details on using hashes here.

Provenance

The following attestation bundles were made for lokit_python-0.2.0-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.2.0-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.2.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 29622431e6af0764f26415b1e7e4a5211ae84124fe0d700827933f8a13f873d0
MD5 3b620f344832d8610e26fe9d21d6be3b
BLAKE2b-256 f0ca71bcc6c7c6222f2a4a6ab31d3afa6777aff04c1b5d152a89f2a5a03ef6fb

See more details on using hashes here.

Provenance

The following attestation bundles were made for lokit_python-0.2.0-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.2.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for lokit_python-0.2.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 11435ff7b59f2a27f2058df9e2e2730ca98b0c39de98430c85fe8623f797796a
MD5 fdf2f4b5d7a91e3da3b922879d4bd534
BLAKE2b-256 c0ead713535e5557559c7b0007f495af562d2f7672e615b5044171f8025af902

See more details on using hashes here.

Provenance

The following attestation bundles were made for lokit_python-0.2.0-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.2.0-cp312-cp312-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for lokit_python-0.2.0-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 29261b54115f4fed52910473d4735ae755e717324b636260f9d4d625f35002df
MD5 39f18c108256b09543d7a043337f75da
BLAKE2b-256 4db7e25a949390fc25c06f3ebe942c5fbcc9111b33849e6c3916d2ae443fbe0c

See more details on using hashes here.

Provenance

The following attestation bundles were made for lokit_python-0.2.0-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