Skip to main content

Base64 encoding without Python's base64 flaws. Output urlsafe without padding, as str. Decodes any variant with or without padding, with validation.

Project description

URL-safe 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 cleaner output
  • String output: Returns proper strings instead of bytes (unlike Python's standard library)
  • 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

Base64 encode bytes to a URL-safe string without padding.

dec(s: str, *, validate=True) -> bytes

Decode URL-safe Base64 into bytes. Padding optional. Set validate=False to silently ignore any unknown characters (Python base64 default behavior).

enc_lines(data: bytes, length: int = 76) -> str

Encode with newlines inserted every length characters.

dec_lines(s: str) -> bytes

Decode formatted input, ignoring all whitespace (but not other unknown characters).

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

base64url-1.1.0.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

base64url-1.1.0-py3-none-any.whl (2.7 kB view details)

Uploaded Python 3

File details

Details for the file base64url-1.1.0.tar.gz.

File metadata

  • Download URL: base64url-1.1.0.tar.gz
  • Upload date:
  • Size: 3.5 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

Hashes for base64url-1.1.0.tar.gz
Algorithm Hash digest
SHA256 6040c5cc523b0c4b3fb48e87e3f027a66a13a0b26334403534821c486104950e
MD5 37dff311ebf38f270a11c4ff00758503
BLAKE2b-256 603d3bc2d96dd719cd79306b9ca39d1a96de119ad9abc37a367a2574a601a0e6

See more details on using hashes here.

File details

Details for the file base64url-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: base64url-1.1.0-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

Hashes for base64url-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 35c90c6afd932c3280b6ff15265435c0a1fa1c24dbb3bed50fdc8bb4ddf525ad
MD5 323e92e459eef8b8c76c3ef827935895
BLAKE2b-256 98f41d2c213e7b7f14f9c625ee7d16a37b5fef864ed2921259d5ce347d87725c

See more details on using hashes here.

Supported by

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