Metadata-Version: 2.4
Name: base64url
Version: 1.1.1
Summary: Base64 encoding without Python's base64 flaws. Output urlsafe without padding, as str. Decodes any variant with or without padding, with validation.
Project-URL: Homepage, https://git.zi.fi/leo/base64url-python
Project-URL: Repository, https://github.com/LeoVasanko/base64url-python
Author: Leo Vasanko
Keywords: b64url,base64,urlsafe_b64decode,urlsafe_b64encode
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: License :: Public Domain
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Utilities
Requires-Python: >=3.8
Description-Content-Type: text/markdown

# 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

```sh
pip install base64url
```

Or for your project using [UV](https://docs.astral.sh/uv/getting-started/installation/):
```sh
uv add base64url
```

## Usage

```python
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.
