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.15.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.15-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for base62_py-1.3.15.tar.gz
Algorithm Hash digest
SHA256 4787ae6c081422e4826a4f4d87907eb5311d57c3250235941a29cc45b90d0314
MD5 27ba895f8866e7803170d0fdaad55daa
BLAKE2b-256 5a2f6318198b3d204dc31b1c6d360a04b196b35c189ba489211a8d035409895e

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for base62_py-1.3.15-py3-none-any.whl
Algorithm Hash digest
SHA256 8f5d7392e356e1bdee13aa60d6feffc8ff7749b86850e86b4492e22821c936fc
MD5 5389681bc01717356084e630878780ee
BLAKE2b-256 cdaf52c92d8b06685e927bef037ff7207f07f551175185518328297025bfb154

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