from baseconv import BaseConverter from string import ascii_lowercase, ascii_uppercase # We have to create this collection ourselves because we want uppercase then # lowercase, and string.ascii_letters is lowercase then uppercase. chars = ascii_uppercase + ascii_lowercase conv = BaseConverter(chars) class AbcIdConverter: regex = '[a-zA-Z]+' def to_python(self, value: str) -> int: return int(conv.decode(value)) def to_url(self, value: int) -> str: return conv.encode(value)