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, is_valid_base62

value = 18969

encoded = encode(value)

# 4VX
print(encoded)

decoded = decode(encoded)

assert value == decoded

assert is_valid_base62(encoded)

Tests

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

License

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


© 2021-2026 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.16.tar.gz (4.7 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.16-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: base62_py-1.3.16.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.2

File hashes

Hashes for base62_py-1.3.16.tar.gz
Algorithm Hash digest
SHA256 c9671b9ce643a3efaae8b6cbaa14b8ffc63ec581970df58d60b28e08363189a1
MD5 0dd2d18305ab9270bda07e3b281e6e6d
BLAKE2b-256 6b9541e8befd8e0adb6618a950c9df17c094d8a926e9c9739250c74e774b8afb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: base62_py-1.3.16-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.2

File hashes

Hashes for base62_py-1.3.16-py3-none-any.whl
Algorithm Hash digest
SHA256 ed82b8f97e322fb5c3fd8f23826420a8f0e46f94ac21b4c5fcce1a498eec1f5e
MD5 d48afb701731c9b5997a09c3c3a7be02
BLAKE2b-256 21e1877b87ee51b279ad9e51f987af632a7361bdaeef2ce330682eabe512eaac

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