Skip to main content

an enum `AutoName` from python docs with multiple stringcase options

Project description

autoname

an enum AutoName from python docs with multiple stringcase options.

Get Started

$ pip install autoname
from autoname import AutoName
from enum import auto


# an enum class
class GameType(AutoName):
    INDIE = auto()


print(GameType.INDIE.value)  # "INDIE"

# could be alternative in pydantic instead of literal
from pydantic import BaseModel


class Game(BaseModel):
    type: GameType

Also have others stringcases coverter

  1. AutoNameLower - convert name value to lowercase
  2. AutoNameUpper - convert name value to uppercase

e.g.

from autoname import AutoNameLower
from enum import auto

class GameType(AutoNameLower):
    INDIE = auto()

print(GameType.INDIE.value) # "indie"

You could also bring your own case convertion algorithm.

from autoname import AutoName, transform
from enum import auto


@transform(function=str.lower)
class GameType(AutoName):
    INDIE = auto()


print(GameType.INDIE.value)  # "indie"

If the autoname is not a sound variable name. there are alias too.

  • StrEnum = AutoName
  • LowerStrEnum = AutoNameLower
  • UpperStrEnum = AutoNameUpper

e.g.

from autoname import StrEnum, transform
from enum import auto


class GameType(StrEnum):
    INDIE = auto()


print(GameType.INDIE.value)  # "INDIE"

Alternative

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

autoname-2.1.0.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

autoname-2.1.0-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file autoname-2.1.0.tar.gz.

File metadata

  • Download URL: autoname-2.1.0.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.1 CPython/3.9.12 Windows/10

File hashes

Hashes for autoname-2.1.0.tar.gz
Algorithm Hash digest
SHA256 70230d481a6ffede9538b10c046d4cf0111809c07d750f66f4a9655c728c4c4a
MD5 921fb6c502395bc0bbd330b196160efe
BLAKE2b-256 802f5263cc73cb71cdfc943a50b2111c4b0fdc941bb090b6183b4234ad447071

See more details on using hashes here.

Provenance

File details

Details for the file autoname-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: autoname-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.1 CPython/3.9.12 Windows/10

File hashes

Hashes for autoname-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ab889c62c94062c32e926ab582464fb913714262723be8d758ffba05a1994d23
MD5 b81a8f114adf320bd9b56c8a20dc023e
BLAKE2b-256 d1ce27bb0986553cf3e241f6543f580e359707937706d4d46b9e7b784ae45e57

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page