{"id":4314,"library":"unpaddedbase64","title":"Unpadded Base64","description":"The `unpaddedbase64` library provides functionality to encode and decode Base64 strings that explicitly omit the '=' padding characters. While RFC 4648 specifies that Base64 should be padded to a multiple of 4 bytes, many protocols choose to leave out this padding. The current version is 2.1.0, released in March 2021, and the library has an infrequent release cadence.","status":"active","version":"2.1.0","language":"python","source_language":"en","source_url":"https://github.com/matrix-org/python-unpaddedbase64","tags":["base64","encoding","decoding","unpadded","rfc4648"],"install":[{"cmd":"pip install unpaddedbase64","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"unpaddedbase64","correct":"import unpaddedbase64"}],"quickstart":{"code":"import unpaddedbase64\n\n# Encode a byte string to unpadded Base64\ndata_bytes = b'\\x00\\x01\\x02'\nencoded_string = unpaddedbase64.encode_base64(data_bytes)\nprint(f\"Encoded: {encoded_string}\")\nassert encoded_string == 'AAEC'\n\n# Decode an unpadded Base64 string back to bytes\ndecoded_bytes = unpaddedbase64.decode_base64('AAEC')\nprint(f\"Decoded: {decoded_bytes}\")\nassert decoded_bytes == data_bytes\n\n# Example with a string that would typically have padding\nlong_data = b'This is a test string.'\nencoded_long = unpaddedbase64.encode_base64(long_data)\nprint(f\"Encoded long: {encoded_long}\")\n# assert encoded_long == 'VGhpcyBpcyBhIHRlc3Qgc3RyaW5nLg' (original would be 'VGhpcyBpcyBhIHRlc3Qgc3RyaW5nLg==')\n\ndecoded_long = unpaddedbase64.decode_base64(encoded_long)\nprint(f\"Decoded long: {decoded_long}\")\nassert decoded_long == long_data","lang":"python","description":"This quickstart demonstrates how to encode byte strings into unpadded Base64 and decode them back using `unpaddedbase64.encode_base64` and `unpaddedbase64.decode_base64`."},"warnings":[{"fix":"Always 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)`.","message":"Python'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.","severity":"gotcha","affected_versions":"All versions of `unpaddedbase64` when interacting with Python's standard `base64` module."},{"fix":"If 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.","message":"This 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).","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'2.1.0':47 '2021':51 '4':33 '4648':22 'base64':2,12,25,60 'byte':34 'cadenc':59 'charact':19 'choos':37 'current':44 'decod':11,62 'encod':9,61 'explicit':15 'function':7 'infrequ':57 'leav':39 'librari':5,54 'mani':35 'march':50 'multipl':31 'omit':16 'pad':18,28,42 'protocol':36 'provid':6 'releas':48,58 'rfc':21 'rfc4648':64 'specifi':23 'string':13 'unpad':1,63 'unpaddedbase64':4 'version':45","created_at":"2026-04-12T03:50:05.013767+00:00","updated_at":"2026-04-16T23:57:35.228272+00:00","problems":[{"fix":"Run `pip install unpaddedbase64` in your terminal to install the library.","cause":"The `unpaddedbase64` package is not installed in the current Python environment.","error":"ModuleNotFoundError: No module named 'unpaddedbase64'"},{"fix":"Use the correct function names provided by `unpaddedbase64`, such as `encode_base64_unpadded` or `decode_base64_unpadded`.","cause":"The user is attempting to call a function name (`b64encode`) from Python's standard `base64` module on the `unpaddedbase64` library.","error":"AttributeError: module 'unpaddedbase64' has no attribute 'b64encode'"},{"fix":"Convert the string to bytes using `.encode()` (e.g., `my_string.encode('utf-8')`) before passing it to the `unpaddedbase64` function.","cause":"The encoding/decoding functions in `unpaddedbase64` expect byte-like objects as input, but a Python string was provided.","error":"TypeError: a bytes-like object is required, not 'str'"},{"fix":"Remove 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.","cause":"The input Base64 string contains padding characters (`=`) which `unpaddedbase64` is not designed to handle during decoding, or the padding is malformed for standard Base64.","error":"binascii.Error: Incorrect padding"},{"fix":"Ensure the input string is a valid Base64-encoded string (containing only A-Z, a-z, 0-9, +, /) before attempting to decode it.","cause":"The input string provided to a `unpaddedbase64` decoding function contains characters that are not valid Base64 digits.","error":"binascii.Error: Non-base64 digit found"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"2.1.0","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/matrix-org/python-unpaddedbase64","docs":null,"changelog":null,"pypi":"https://pypi.org/project/unpaddedbase64/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-29","next_check":"2026-07-28","install_tag":null}}