Skip to main content

Custom Base-62 Encoder in Python

Project description

base62-ts

Custom Base-62 Encoder

GitHub tag (latest by date) GitHub last commit GitHub issues PyPI - Version

This repository contains the version of my encoder/decoder for Base-62 in three languages:

Motivation

I needed an efficient way to apply a Base-62 encoding/decoding algorithm working the same way in TypeScript/Javascript, Golang and Python environments.

Usage

Both versions use the same following dictionary:

Value Character Value Character Value Character Value Character Value Character
0 0 13 d 26 q 39 D 52 Q
1 1 14 e 27 r 40 E 53 R
2 2 15 f 28 s 41 F 54 S
3 3 16 g 29 t 42 G 55 T
4 4 17 h 30 u 43 H 56 U
5 5 18 i 31 v 44 I 57 V
6 6 19 j 32 w 45 J 58 W
7 7 20 k 33 x 46 K 59 X
8 8 21 l 34 y 47 L 60 Y
9 9 22 m 35 z 48 M 61 Z
10 a 23 n 36 A 49 N
11 b 24 o 37 B 50 O
12 c 25 p 38 C 51 P

In other words, they use the following base: 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.

pip install base62-py
from base62 import decode, encode

value = 18969

encoded = encode(value)

# 4VX
print(encoded)

decoded = decode(encoded)

assert value == decoded

Tests

$ pip install -e . && python3 -m unittest discover

License

Both versions are available under a MIT license (see LICENSE).


© 2021-2025 Cyril Dever. All rights reserved.

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

base62_py-1.3.14.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

base62_py-1.3.14-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file base62_py-1.3.14.tar.gz.

File metadata

  • Download URL: base62_py-1.3.14.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.31.0 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.3 CPython/3.10.2

File hashes

Hashes for base62_py-1.3.14.tar.gz
Algorithm Hash digest
SHA256 d4f75d7abe3fc29b784d2897088e24747848403d39eeaf0ba2326b3d0025ca60
MD5 7c17f40ce74324d1827a639f35443395
BLAKE2b-256 327bdfe9942080810d6d8541630766af42b34ad98a9817f350ddfc3a33ef41d2

See more details on using hashes here.

File details

Details for the file base62_py-1.3.14-py3-none-any.whl.

File metadata

  • Download URL: base62_py-1.3.14-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.31.0 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.3 CPython/3.10.2

File hashes

Hashes for base62_py-1.3.14-py3-none-any.whl
Algorithm Hash digest
SHA256 2db3169ad05f93bd2a394c3cd88e2127c13655db416b48bc4f78c3e763995c0f
MD5 83f567d3c1badb05d2b2bb7ecf05ae42
BLAKE2b-256 800675514dc22b91ddf1c60ccb600bac4175ea17c89ba0794a966a6a22e003c8

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