Python module for base62 encoding; a URL-safe encoding for arbitrary data
Clone or download
Latest commit b6a2403 Jul 31, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
tests Support both types of charset Jul 30, 2018
.gitignore Initial commit. Apr 14, 2013
.travis.yml Drop support for Python 2.6 Jun 5, 2018
LICENSE Adopt BSD license Jan 24, 2014
README.rst Update README Jul 30, 2018 Support both types of charset Jul 30, 2018 Long description and description May 21, 2017



Build Status Coveralls PyPI

A Python module for base62 encoding. Ported from PHP code that I wrote in mid-2000, which can be found here.


When writing a web application, often times we would like to keep the URLs short.


This certainly gives a more concise look than the following.


This was the original motivation to write this module, but there shall be much more broader potential use cases of this module. The main advantage of base62 is that it is URL-safe (as opposed to base64) due to the lack of special characters such as '/' or '='. Another key aspect is that the alphabetical orders of the original (unencoded) data is preserved when encoded. In other words, encoded data can be sorted without being decoded at all.


base62 can be installed via pypi. Unfortunately, the package name base62 on pypi had already been occupied by someone else, so we had to go by pybase62.

pip install pybase62

Alternatively, you may clone the code to manually install it.

git clone
cd base62 && python install


The following section describes a basic usage of base62.

>>> import base62

>>> base62.encode(34441886726)

>>> base62.decode('base62')

From version 0.2.0, base62 supports bytes array encoding as well.

>>> base62.encodebytes(b'\0')

>>> base62.encodebytes(b'\xff\xff')

>>> base62.decodebytes('0')

>>> base62.decodebytes('1')


You may run some test cases to ensure all functionalities are operational.

py.test -v

If pytest is not installed, you may want to run the following commands:

pip install -r tests/requirements.txt


Deploy a source package (to pypi) as follows:

python sdist upload