Skip to main content
Hetman Logo

Hetman Kit Localize provides thread-safe locale management using context variables. It enables concurrent execution with different locale settings per context.

Installation

pip install hetman-kit-localize

Why use this?

Managing locale settings in concurrent applications can be challenging. Hetman Kit Localize allows you to:

  1. Thread-Safe Locale Management: Use context variables to ensure each execution context has its own locale.
  2. Simple API: Easy-to-use class methods for getting and setting locales.
  3. Base Locale Support: Define a default locale that serves as a fallback.
  4. Concurrent Execution: Perfect for async applications where different requests need different locales.

Usage Example

Setting Up Locales

Set the base locale once during application initialization:

from hetman_kit_localize import Localize

# Set the base (default) locale
Localize.set_base_locale("en")

Getting and Setting Locales

from hetman_kit_localize import Localize

# Set up the base locale first
Localize.set_base_locale("en")

# Get the current locale (returns base locale if not set)
print(Localize.get_locale())  # Output: en

# Set a different locale for the current context
Localize.set_locale("pl")
print(Localize.get_locale())  # Output: pl

# Get the base locale
print(Localize.get_base_locale())  # Output: en

Context-Aware Example

The locale management is context-aware, making it perfect for web applications where each request might need a different locale:

from hetman_kit_localize import Localize
import asyncio


async def handle_request(locale: str):
    # Each request can have its own locale
    Localize.set_locale(locale)

    # This will return the locale for this specific context
    current = Localize.get_locale()
    print(f"Handling request with locale: {current}")


# Set the base locale
Localize.set_base_locale("en")


async def main():
    await asyncio.gather(
        handle_request("pl"),
        handle_request("en"),
        handle_request("de"),
    )


# Simulate concurrent requests with different locales
asyncio.run(main())

Resolving Translations

The resolve_translation() method helps you retrieve the correct translation from a dictionary based on the current locale:

from hetman_kit_localize import Localize

# Set up locales
Localize.set_base_locale("en")

# Define translations
messages = {
    "en": "Hello, World!",
    "pl": "Witaj, Świecie!",
    "de": "Hallo, Welt!"
}

# Get translation for current locale (falls back to base locale)
Localize.set_locale("pl")
print(Localize.resolve_translation(messages))  # Output: Witaj, Świecie!

Localize.set_locale("de")
print(Localize.resolve_translation(messages))  # Output: Hallo, Welt!

# If locale is not found, falls back to base locale
Localize.set_locale("fr")
print(Localize.resolve_translation(messages))  # Output: Hello, World!

# Use strict=False to return None instead of raising KeyError when neither locale nor base locale exists
partial_messages = {"pl": "Witaj!"}
Localize.set_locale("en")
print(Localize.resolve_translation(partial_messages, strict=False))  # Output: None

Core Features

  • Thread-Safe: Uses Python's contextvars for safe concurrent locale management.
  • Simple API: Just four class methods: set_base_locale(), get_base_locale(), set_locale(), get_locale().
  • Context Variables: Each execution context maintains its own locale state.

Why "Kit"?

This package is called Hetman Kit Localize because it's designed to be a building block ("kit") for your own i18n solutions. Other classes can inherit from Localize to easily add locale management to their functionality:

from hetman_kit_localize import Localize

class MyI18nClass(Localize):
    MESSAGES = {
        "welcome": {
            "en": "Welcome!",
            "pl": "Witaj!",
            "de": "Willkommen!"
        },
        "goodbye": {
            "en": "Goodbye!",
            "pl": "Do widzenia!",
            "de": "Auf Wiedersehen!"
        }
    }
    
    @classmethod
    def get_message(cls, key: str) -> str:
        # Use resolve_translation to get the right message
        return cls.resolve_translation(cls.MESSAGES[key])

# Inherits all locale management methods
MyI18nClass.set_base_locale("en")
MyI18nClass.set_locale("pl")
print(MyI18nClass.get_locale())  # Output: pl
print(MyI18nClass.get_message("welcome"))  # Output: Witaj!

MyI18nClass.set_locale("de")
print(MyI18nClass.get_message("goodbye"))  # Output: Auf Wiedersehen!

By inheriting from Localize, your classes automatically get thread-safe locale management without any additional setup!

Metadata

Release files for hetman-kit-localize 1.0.1

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

Source distribution (sdist)

Source distribution for hetman-kit-localize 1.0.1
File Size Uploaded Provenance Actions
hetman_kit_localize-1.0.1.tar.gz 8.0 kB With provenance Details for hetman_kit_localize-1.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hetman-kit-localize 1.0.1
File Interpreter ABI Platform Actions
hetman_kit_localize-1.0.1-py3-none-any.whl Python 3 none any Details for hetman_kit_localize-1.0.1-py3-none-any.whl

Total release size: 16.8 kB

Release files / hetman_kit_localize-1.0.1.tar.gz

Download URL hetman_kit_localize-1.0.1.tar.gz
Size 8.0 kB
Tags Source
SHA-256 checksum
How to use checksums
6c6b25318243e6f5447f4e1b4ed4da446c8f3ac10d178ef42cd0b786b72c342d
BLAKE2b-256 checksum
How to use checksums
26dea386afde96ef0a49c9ec9e76ae8d58c09692b221accae95a0cda628240fb
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 Jan 21, 2026.

Transparency log

Release files / hetman_kit_localize-1.0.1-py3-none-any.whl

Download URL hetman_kit_localize-1.0.1-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
37d5f210dd475f7afbabbd3f7a336bf76be4b289be2be49bd2ae3be73e8ddcb7
BLAKE2b-256 checksum
How to use checksums
ed1208101abf8cd822a4d81504098d437179db12364a2b49826c53ebd43d0b67
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 Jan 21, 2026.

Transparency log

Security for hetman-kit-localize 1.0.1

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 hetman_kit_localize-1.0.1.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 Jan 21, 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.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files Full provenance

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