Skip to main content

Library for optimizing enum constant values

Project description

microconst

pypi python typed tests license

Replace long constant names with 2 ASCII keys

Installation

pip:

pip install microconst

poetry:

poetry add microconst

Features

Constants

Every call of flag or key generates 2-character key. This key is represented as left and right indexes of f"{ascii_letters}{digits}" str. Each time the left index reaches cap, it resets to 0 and right index increments.
After reaching both of caps, next call of function will throw OverflowError. Current maximum count of keys is 3844.

Typing

key function requires value_type argument, such as str, int etc. This type used in both static analysis and type convertion with Key.parse_entry(data) function.

Examples

Main purpose of this library is making telegram bot's "callback_data" much more compact because of 64-byte limit. You can see more realistic example here

Flag usage:

from microconst import flag

# Autogenerates unique pairs of characters
class Status:
    PENDING = flag()
    APPROVED = flag()
    REJECTED = flag()

assert Status.PENDING == "aa"
assert Status.APPROVED == "ba"
assert Status.REJECTED == "ca"

Key usage:

from microconst import key, parse_entry

USER = key(str)

# You can call keys to create key-value pair (acts same as concat)
username = USER("name") 
# Getting value
value = USER.parse_entry(username) 

assert username == "aaname"
assert value == "name"

# You can use seperate function or method. Method doesnt require type argument
assert parse_entry(username, str) == value

License

MIT

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

microconst-0.1.0.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

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

microconst-0.1.0-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file microconst-0.1.0.tar.gz.

File metadata

  • Download URL: microconst-0.1.0.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for microconst-0.1.0.tar.gz
Algorithm Hash digest
SHA256 17e1cf0372064989f4ec724c9cd51911c8d6d0d76310fa3a3f06e0e7669c5ffa
MD5 d24ddd8f23ec76d8a598392b5c83a3a6
BLAKE2b-256 7c9b141480ddc858b5dafe9ac217859267230a254c7475e2f6c504c69b308669

See more details on using hashes here.

File details

Details for the file microconst-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: microconst-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for microconst-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 437dee6630724f266737ac6fdf324a72c20e3353062988899524b8150f3dd9d7
MD5 2505dee89d5691faf627a509e85b986f
BLAKE2b-256 3b16d0e8363f35f5dd786c817515ce34468c5e48fd589b5f1dd9b64b955a32d4

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