Skip to main content

Fast Base64 encoding/decoding

Project description

Fast Base64 implementation

license-status pypi-status Documentation Status travis-status appveyor-status codecov-status

This project is a wrapper on libbase64.

It aims to provide a fast base64 implementation for base64 encoding/decoding.

Installation

pip install pybase64

Usage

pybase64 uses the same API as Python base64 “modern interface” (introduced in Python 2.4) for an easy integration.

To get the fastest decoding, it is recommended to use the pybase64.b64decode and validate=True when possible.

import pybase64

print(pybase64.b64encode(b'>>>foo???', altchars='_:'))
# b'Pj4_Zm9vPz8:'
print(pybase64.b64decode(b'Pj4_Zm9vPz8:', altchars='_:', validate=True))
# b'>>>foo???'

# Standard encoding helpers
print(pybase64.standard_b64encode(b'>>>foo???'))
# b'Pj4+Zm9vPz8/'
print(pybase64.standard_b64decode(b'Pj4+Zm9vPz8/'))
# b'>>>foo???'

# URL safe encoding helpers
print(pybase64.urlsafe_b64encode(b'>>>foo???'))
# b'Pj4-Zm9vPz8_'
print(pybase64.urlsafe_b64decode(b'Pj4-Zm9vPz8_'))
# b'>>>foo???'

A command-line tool is also provided. It has encode, decode and benchmark subcommands.

usage: pybase64 [-h] [-V] {benchmark,encode,decode} ...

pybase64 command-line tool.

positional arguments:
  {benchmark,encode,decode}
                        tool help
    benchmark           -h for usage
    encode              -h for usage
    decode              -h for usage

optional arguments:
  -h, --help            show this help message and exit
  -V, --version         show program's version number and exit

Full documentation on Read the Docs.

Benchmark

Running Python 3.6.0, Apple LLVM version 8.1.0 (clang-802.0.42), Mac OS X 10.12.6 on an Intel Core i7-4870HQ @ 2.50GHz

pybase64 0.2.0 (C extension active - AVX2)
bench: altchars=None, validate=False
pybase64._pybase64.b64encode:     2941.397 MB/s (13,271,472 bytes -> 17,695,296 bytes)
pybase64._pybase64.b64decode:      328.250 MB/s (17,695,296 bytes -> 13,271,472 bytes)
base64.b64encode:                  565.744 MB/s (13,271,472 bytes -> 17,695,296 bytes)
base64.b64decode:                  327.075 MB/s (17,695,296 bytes -> 13,271,472 bytes)
bench: altchars=None, validate=True
pybase64._pybase64.b64encode:     2995.909 MB/s (13,271,472 bytes -> 17,695,296 bytes)
pybase64._pybase64.b64decode:     3996.267 MB/s (17,695,296 bytes -> 13,271,472 bytes)
base64.b64encode:                  577.565 MB/s (13,271,472 bytes -> 17,695,296 bytes)
base64.b64decode:                  104.835 MB/s (17,695,296 bytes -> 13,271,472 bytes)
bench: altchars=b'-_', validate=False
pybase64._pybase64.b64encode:     2237.740 MB/s (13,271,472 bytes -> 17,695,296 bytes)
pybase64._pybase64.b64decode:      262.021 MB/s (17,695,296 bytes -> 13,271,472 bytes)
base64.b64encode:                  313.977 MB/s (13,271,472 bytes -> 17,695,296 bytes)
base64.b64decode:                  219.487 MB/s (17,695,296 bytes -> 13,271,472 bytes)
bench: altchars=b'-_', validate=True
pybase64._pybase64.b64encode:     2349.481 MB/s (13,271,472 bytes -> 17,695,296 bytes)
pybase64._pybase64.b64decode:     2790.047 MB/s (17,695,296 bytes -> 13,271,472 bytes)
base64.b64encode:                  314.182 MB/s (13,271,472 bytes -> 17,695,296 bytes)
base64.b64decode:                   89.855 MB/s (17,695,296 bytes -> 13,271,472 bytes)

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

pybase64-0.2.1.tar.gz (79.1 kB view hashes)

Uploaded Source

Built Distributions

pybase64-0.2.1-cp36-cp36m-win_amd64.whl (30.1 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

pybase64-0.2.1-cp36-cp36m-win32.whl (28.3 kB view hashes)

Uploaded CPython 3.6m Windows x86

pybase64-0.2.1-cp36-cp36m-manylinux1_x86_64.whl (62.5 kB view hashes)

Uploaded CPython 3.6m

pybase64-0.2.1-cp36-cp36m-manylinux1_i686.whl (58.4 kB view hashes)

Uploaded CPython 3.6m

pybase64-0.2.1-cp36-cp36m-macosx_10_6_intel.whl (40.6 kB view hashes)

Uploaded CPython 3.6m macOS 10.6+ intel

pybase64-0.2.1-cp35-cp35m-win_amd64.whl (30.1 kB view hashes)

Uploaded CPython 3.5m Windows x86-64

pybase64-0.2.1-cp35-cp35m-win32.whl (28.2 kB view hashes)

Uploaded CPython 3.5m Windows x86

pybase64-0.2.1-cp35-cp35m-manylinux1_x86_64.whl (62.5 kB view hashes)

Uploaded CPython 3.5m

pybase64-0.2.1-cp35-cp35m-manylinux1_i686.whl (58.4 kB view hashes)

Uploaded CPython 3.5m

pybase64-0.2.1-cp35-cp35m-macosx_10_6_intel.whl (40.6 kB view hashes)

Uploaded CPython 3.5m macOS 10.6+ intel

pybase64-0.2.1-cp34-cp34m-manylinux1_x86_64.whl (62.3 kB view hashes)

Uploaded CPython 3.4m

pybase64-0.2.1-cp34-cp34m-manylinux1_i686.whl (58.3 kB view hashes)

Uploaded CPython 3.4m

pybase64-0.2.1-cp34-cp34m-macosx_10_6_intel.whl (40.5 kB view hashes)

Uploaded CPython 3.4m macOS 10.6+ intel

pybase64-0.2.1-cp33-cp33m-manylinux1_x86_64.whl (61.8 kB view hashes)

Uploaded CPython 3.3m

pybase64-0.2.1-cp33-cp33m-manylinux1_i686.whl (57.8 kB view hashes)

Uploaded CPython 3.3m

pybase64-0.2.1-cp27-cp27mu-manylinux1_x86_64.whl (61.8 kB view hashes)

Uploaded CPython 2.7mu

pybase64-0.2.1-cp27-cp27mu-manylinux1_i686.whl (57.6 kB view hashes)

Uploaded CPython 2.7mu

pybase64-0.2.1-cp27-cp27m-manylinux1_x86_64.whl (61.7 kB view hashes)

Uploaded CPython 2.7m

pybase64-0.2.1-cp27-cp27m-manylinux1_i686.whl (57.6 kB view hashes)

Uploaded CPython 2.7m

pybase64-0.2.1-cp27-cp27m-macosx_10_6_intel.whl (40.5 kB view hashes)

Uploaded CPython 2.7m macOS 10.6+ intel

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page