Install & Compatibility
Where this runs
tested against v2.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
unpaddedbase64
✓ import unpaddedbase64
This quickstart demonstrates how to encode byte strings into unpadded Base64 and decode them back using `unpaddedbase64.encode_base64` and `unpaddedbase64.decode_base64`.
import unpaddedbase64
# Encode a byte string to unpadded Base64
data_bytes = b'\x00\x01\x02'
encoded_string = unpaddedbase64.encode_base64(data_bytes)
print(f"Encoded: {encoded_string}")
assert encoded_string == 'AAEC'
# Decode an unpadded Base64 string back to bytes
decoded_bytes = unpaddedbase64.decode_base64('AAEC')
print(f"Decoded: {decoded_bytes}")
assert decoded_bytes == data_bytes
# Example with a string that would typically have padding
long_data = b'This is a test string.'
encoded_long = unpaddedbase64.encode_base64(long_data)
print(f"Encoded long: {encoded_long}")
# assert encoded_long == 'VGhpcyBpcyBhIHRlc3Qgc3RyaW5nLg' (original would be 'VGhpcyBpcyBhIHRlc3Qgc3RyaW5nLg==')
decoded_long = unpaddedbase64.decode_base64(encoded_long)
print(f"Decoded long: {decoded_long}")
assert decoded_long == long_data
Debug
Known issues
gotchaPython's built-in `base64` module by default expects and sometimes requires '=' padding for decoding. Using `base64.b64decode()` with an unpadded string (which this library produces) will often result in a `binascii.Error: Incorrect padding`. This library is specifically designed to handle unpadded Base64.fixAlways use `unpaddedbase64.decode_base64()` to decode strings encoded by this library or other unpadded sources. If you need to convert to a padded string for `base64.b64decode()`, you can manually add padding: `padded_s = s + '=' * (-len(s) % 4)`.
affects: All versions of `unpaddedbase64` when interacting with Python's standard `base64` module.
gotchaThis library handles the *unpadded* aspect of Base64 but does not automatically implement the URL-safe Base64 alphabet. Standard Base64 uses `+` and `/`, which need percent-encoding in URLs. URL-safe Base64 (RFC 4648 §5) replaces these with `-` and `_`. If you require both unpadded and URL-safe encoding, you'll need to handle the character substitution yourself or use `base64.urlsafe_b64encode/decode` (and be mindful of its padding behavior).fixIf URL-safe characters are needed, either manually replace `+` with `-` and `/` with `_` (and vice-versa for decoding) on the output of `unpaddedbase64`, or consider using `base64.urlsafe_b64encode()` if padding is acceptable, then strip padding if necessary.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'unpaddedbase64'
The `unpaddedbase64` package is not installed in the current Python environment.
fixRun `pip install unpaddedbase64` in your terminal to install the library.
AttributeError: module 'unpaddedbase64' has no attribute 'b64encode'
The user is attempting to call a function name (`b64encode`) from Python's standard `base64` module on the `unpaddedbase64` library.
fixUse the correct function names provided by `unpaddedbase64`, such as `encode_base64_unpadded` or `decode_base64_unpadded`.
TypeError: a bytes-like object is required, not 'str'
The encoding/decoding functions in `unpaddedbase64` expect byte-like objects as input, but a Python string was provided.
fixConvert the string to bytes using `.encode()` (e.g., `my_string.encode('utf-8')`) before passing it to the `unpaddedbase64` function. binascii.Error: Incorrect padding
The input Base64 string contains padding characters (`=`) which `unpaddedbase64` is not designed to handle during decoding, or the padding is malformed for standard Base64.
fixRemove any padding characters from the Base64 string before passing it to `decode_base64_unpadded`, or use Python's standard `base64` module if the string is expected to be padded.
binascii.Error: Non-base64 digit found
The input string provided to a `unpaddedbase64` decoding function contains characters that are not valid Base64 digits.
fixEnsure the input string is a valid Base64-encoded string (containing only A-Z, a-z, 0-9, +, /) before attempting to decode it.
Upgrade
Version history
2.1.0latest on PyPI · released Mar 9, 2021
Audit
Dependencies
No dependency data recorded yet.