快速 Base64 编码/解码
项目描述
快速 Base64 实现
这个项目是libbase64的一个包装器。
它旨在为 base64 编码/解码提供快速的 base64 实现。
安装
pip install pybase64
用法
pybase64使用与 Python base64 “现代接口”(在 Python 2.4 中引入)相同的 API,以便于集成。
为了获得最快的解码,建议尽可能使用pybase64.b64decode和validate=True。
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???'
还提供了一个命令行工具。它具有编码、解码和基准测试子命令。
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
阅读文档的完整文档。
基准
在 Intel Core i7-4870HQ @ 2.50GHz 上运行 Python 3.7.2、Apple LLVM 版本 10.0.0 (clang-1000.11.45.5)、Mac OS X 10.14.2
pybase64 0.5.0 (C extension active - AVX2)
bench: altchars=None, validate=False
pybase64._pybase64.encodebytes: 1734.776 MB/s (13,271,472 bytes -> 17,928,129 bytes)
pybase64._pybase64.b64encode: 4039.539 MB/s (13,271,472 bytes -> 17,695,296 bytes)
pybase64._pybase64.b64decode: 1854.423 MB/s (17,695,296 bytes -> 13,271,472 bytes)
base64.encodebytes: 78.352 MB/s (13,271,472 bytes -> 17,928,129 bytes)
base64.b64encode: 539.840 MB/s (13,271,472 bytes -> 17,695,296 bytes)
base64.b64decode: 287.826 MB/s (17,695,296 bytes -> 13,271,472 bytes)
bench: altchars=None, validate=True
pybase64._pybase64.b64encode: 4156.607 MB/s (13,271,472 bytes -> 17,695,296 bytes)
pybase64._pybase64.b64decode: 4107.997 MB/s (17,695,296 bytes -> 13,271,472 bytes)
base64.b64encode: 559.342 MB/s (13,271,472 bytes -> 17,695,296 bytes)
base64.b64decode: 143.674 MB/s (17,695,296 bytes -> 13,271,472 bytes)
bench: altchars=b'-_', validate=False
pybase64._pybase64.b64encode: 2786.776 MB/s (13,271,472 bytes -> 17,695,296 bytes)
pybase64._pybase64.b64decode: 1124.136 MB/s (17,695,296 bytes -> 13,271,472 bytes)
base64.b64encode: 322.427 MB/s (13,271,472 bytes -> 17,695,296 bytes)
base64.b64decode: 205.195 MB/s (17,695,296 bytes -> 13,271,472 bytes)
bench: altchars=b'-_', validate=True
pybase64._pybase64.b64encode: 2806.271 MB/s (13,271,472 bytes -> 17,695,296 bytes)
pybase64._pybase64.b64decode: 2740.456 MB/s (17,695,296 bytes -> 13,271,472 bytes)
base64.b64encode: 314.709 MB/s (13,271,472 bytes -> 17,695,296 bytes)
base64.b64decode: 121.803 MB/s (17,695,296 bytes -> 13,271,472 bytes)
变更日志
1.2.3
更新 base64 库
发布 python 3.11 轮子
1.2.2
更新 base64 库
修复在 musl 发行版上构建的 C 扩展
发布 musllinux 轮子
1.2.1
发布 PyPy 3.8 (pypy38_pp73) 轮子
1.2.0
释放 GIL
发布 CPython 3.10 轮子
放弃对 python 3.5 的支持
1.1.4
添加 macOS arm64 滚轮
1.1.3
GitHub Actions:修复构建标签
1.1.2
添加 PyPy 轮子
添加 aarch64、ppc64le 和 s390x manylinux 轮子
1.1.1
将 CI 从 TravisCI/AppVeyor 移至 GitHub Actions
修复 Linux/macOS 轮子的发布
1.1.0
添加 b64encode_as_string,与 b64encode 相同,但返回 str 对象而不是 bytes 对象
添加 b64decode_as_bytearray,与 b64decode 相同,但返回的是 bytearray 对象而不是 bytes 对象
从 UCS1 字符串加速解码
1.0.2
更新 base64 库
发布 python 3.9 轮子
1.0.1
发布 python 3.8 轮子
1.0.0
放弃对 python 3.4 的支持
放弃对 python 2.7 的支持
0.5.0
发布 python 3.7 轮子
放弃对 python 3.3 的支持
0.4.0
validate==False 时加速解码
0.3.1
修复部署问题
0.3.0
添加 encodebytes 函数
0.2.1
修复了 Windows 上的无效结果
0.2.0
添加的文档
在主脚本中添加了子命令:
帮助
版本
编码
解码
基准
0.1.2
更新了 base64 原生库
0.1.1
修复了部署问题
0.1.0
首次公开发布
项目详情
下载文件
下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。