Skip to main content
Hetman Logo

Hetman Codetable provides centralized, standardized response codes for APIs and applications. It ensures consistency by treating codes as a single source of truth.

Installation

pip install hetman-codetable

Why use this?

Managing response codes and messages across an application can become chaotic. Hetman Codetable allows you to:

  1. Centralize all your application codes and messages in one place.
  2. Standardize API responses with consistent error codes and messages.
  3. Internationalize (i18n) messages easily, switching languages dynamically.

Usage Example

Defining Codetables

You can organize your codes into multiple classes for better structure, even while sharing the same namespace.

from codetable import Codetable, msg, i18n

# 1. Set the base locale (Critical for i18n)
i18n.set_base_locale("en")

class UserError(Codetable):
    NAMESPACE = "user"

    NOT_FOUND = msg("User not found.")

    ALREADY_EXISTS = i18n(
        en="User already exists.",
        pl="Użytkownik już istnieje.",
    )

class UserSuccess(Codetable):
    NAMESPACE = "user"

    CREATED = msg("User created successfully.")

    UPDATED = i18n(
        en="User updated successfully.",
        pl="Użytkownik został zaktualizowany pomyślnie.",
    )

Accessing Codes

# --- 1. Accessing Standard Codes ---
print(UserError.NOT_FOUND)
# Output: {'code': 'user.not_found', 'msg': 'User not found.'}

print(UserSuccess.CREATED)
# Output: {'code': 'user.created', 'msg': 'User created successfully.'}

# --- 2. Accessing i18n Codes (Default: English, i18n.set_base_locale("en")) ---
print(UserError.ALREADY_EXISTS)
# Output: {'code': 'user.already_exists', 'msg': 'User already exists.'}

# --- 3. Switching Locales (for all i18n codes) ---
i18n.set_locale("pl")

print(UserError.ALREADY_EXISTS)
# Output: {'code': 'user.already_exists', 'msg': 'Użytkownik już istnieje.'}

print(UserSuccess.UPDATED)
# Output: {'code': 'user.updated', 'msg': 'Użytkownik został zaktualizowany pomyślnie.'}

Lazy Load

i18n.set_locale("en")

error = UserError.lazy("ALREADY_EXISTS")

print(error())
# Output: {'code': 'user.already_exists', 'msg': 'User already exists.'}

success = UserSuccess.lazy("UPDATED")

print(success())
# Output: {'code': 'user.updated', 'msg': 'User updated successfully.'}

Customizing Key Maps

You can custom output keys globally or per-table by modifying the key_map.

# Change default keys globally
Codetable.key_map = {"code": "error_code", "value": "message"}

print(UserError.ALREADY_EXISTS)
# Output: {'error_code': 'user.already_exists', 'message': 'Użytkownik już istnieje.'}

Core Features

  • Namespace Management: Automatically prefixes codes with the table's namespace (e.g., user.not_found).
  • Strict Typing: Built with Python type hints for excellent IDE support.
  • Dynamic Descriptor Protocol: Codes know their own variable names and parent tables automatically.
  • Context-Aware I18n: Uses contextvars to handle per-request locales safely in async environments.

Metadata

Release files for hetman-codetable 1.0.3

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-codetable 1.0.3
File Size Uploaded Provenance Actions
hetman_codetable-1.0.3.tar.gz 9.0 kB With provenance Details for hetman_codetable-1.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hetman-codetable 1.0.3
File Interpreter ABI Platform Actions
hetman_codetable-1.0.3-py3-none-any.whl Python 3 none any Details for hetman_codetable-1.0.3-py3-none-any.whl

Total release size: 19.2 kB

Release files / hetman_codetable-1.0.3.tar.gz

Download URL hetman_codetable-1.0.3.tar.gz
Size 9.0 kB
Tags Source
SHA-256 checksum
How to use checksums
8e044a76b9b4ead2b458ec19d5fab9f01eb0b4f160c3958cd2180a81cf67ad5e
BLAKE2b-256 checksum
How to use checksums
05f4b42e1f1db6bac0ebb442243314f1a64975328820ee110025c8f5bd0ddd17
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 22, 2026.

Transparency log

Release files / hetman_codetable-1.0.3-py3-none-any.whl

Download URL hetman_codetable-1.0.3-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c6413365e02dc93050a7b019bbf56c92057833b4f17d2244273e7f6a51ddc9c7
BLAKE2b-256 checksum
How to use checksums
4ae19225b44f16cdfb46489ba1f1667e69f9b96a6b1e1c483a3d2289ebe9f004
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 22, 2026.

Transparency log

Security for hetman-codetable 1.0.3

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_codetable-1.0.3.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 22, 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