Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Python module for base62 encoding

Project Description

base62

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

Rationale

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

http://localhost/post/V1Biicwt

This certainly gives a more concise look than the following.

http://localhost/post/109237591284123

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.

Installation

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 https://github.com/suminb/base62
cd base62 && python setup.py install

Usage

The following section describes a basic usage of base62.

>>> import base62

>>> base62.encode(34441886726)
'base62'

>>> base62.decode('base62')
34441886726

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

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

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

>>> base62.decodebytes('0')
b''

>>> base62.decodebytes('1')
b'\x01'

Tests

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
Release History

Release History

This version
History Node

0.3.2

History Node

0.3.1

History Node

0.3.0

History Node

0.2.0

History Node

0.1.3

History Node

0.1.2

History Node

0.1.1

History Node

0.1.0

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
pybase62-0.3.2.tar.gz (2.7 kB) Copy SHA256 Checksum SHA256 Source Jun 27, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting