Base64 encoding without Python's base64 flaws. Output urlsafe without padding, as str. Decodes any variant with or without padding, with validation.
Project description
Urlsafe Base64 for Python
A simple module for encoding without padding, fixing Python standard library's flaws.
Replaces the standard library's base64.urlsafe_b64encode and base64.urlsafe_b64decode with a cleaner implementation that returns strings instead of bytes and avoids unnecessary padding.
Features
- Urlsafe: Uses only characters that are safe for URLs and filenames
- No padding: Removes trailing
=characters for a cleaner, actually urlsafe output - String output: Returns Base64 as str instead of bytes
- Fast: Based on Python stdlib, with constant-time padding restoration
Installation
pip install base64url
Or for your project using UV:
uv add base64url
Usage
import base64url
text = base64url.enc(bytes(4)) # Returns "AAAAAA"
data = base64url.dec(text) # Recovers the bytes
enc(data: bytes) -> str
Encode bytes to a urlsafe string without padding.
dec(s: str, *, validate=True) -> bytes
Decode standard or urlsafe Base64 into bytes. Padding optional. Raises binascii.Error (ValueError) on invalid input. Set validate=False to silently ignore unknown characters (Python base64 default behavior).
enc_lines(data: bytes, length=76, sep="\n") -> str
Encode with newlines inserted every length characters. Does not add a newline at the end.
dec_lines(s: str) -> bytes
Decode formatted input, ignoring whitespace. Raises binascii.Error on invalid characters.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file base64url-1.1.1.tar.gz.
File metadata
- Download URL: base64url-1.1.1.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c7accac6a116299bebbd1fbb83b8a3b6192ac5bee5bc53d88e7fb79f99d29e6b
|
|
| MD5 |
968883259c7cd325384ecf66989775ba
|
|
| BLAKE2b-256 |
17d59d749f7b55f734be709c1c78e7100abeee4559b4139a782df638f4592298
|
File details
Details for the file base64url-1.1.1-py3-none-any.whl.
File metadata
- Download URL: base64url-1.1.1-py3-none-any.whl
- Upload date:
- Size: 2.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
455ff8619739fdd118e01ef5990e821b272fb29ad7e8b27a08fa21c1bd6ccdd7
|
|
| MD5 |
eea0dcac4a22f027ce3090bd7f1db380
|
|
| BLAKE2b-256 |
05be4041fd20bcedf32755427bc409f058118d979c8381ce0008aa89776fac73
|