Metadata-Version: 2.3
Name: durl-py
Version: 0.1.1
Summary: Simple Data URL Model
License: MIT
Author: Allen Chou
Author-email: f1470891079@gmail.com
Requires-Python: >=3.11,<4
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Dist: dictpress (>=0.3.0)
Requires-Dist: pydantic (>=2)
Requires-Dist: rich
Requires-Dist: str-or-none
Project-URL: Homepage, https://github.com/allen2c/durl-py
Project-URL: PyPI, https://pypi.org/project/durl-py/
Project-URL: Repository, https://github.com/allen2c/durl-py
Description-Content-Type: text/markdown

# durl-py

A lightweight Python library for working with Data URLs (RFC 2397).

## Installation

```bash
pip install durl-py
```

## Usage

### DataURL Class

The `durl.DataURL` class provides a convenient way to create, parse, and manipulate Data URLs.

**Creating a DataURL from raw data:**

```python
from durl import DataURL, MIMEType

# From bytes
data_url = DataURL.from_data(MIMEType.TEXT_PLAIN, b"Hello, World!")
print(data_url.url)
# data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==

# From string
data_url = DataURL.from_data(MIMEType.TEXT_PLAIN, "Hello, World!")
print(data_url.url)
# data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==
```

**Parsing a DataURL string:**

```python
from durl import DataURL

data_url_string = "data:text/plain;base64,SGVsbG8sIFdvcmxkIQ=="
data_url = DataURL.from_url(data_url_string)

print(data_url.mime_type)
# text/plain

print(data_url.data_decoded)
# Hello, World!
```

### `message_contents_from_text` function

The `durl.message_contents_from_text` function allows you to extract Data URLs from a string.

```python
from durl import message_contents_from_text, DataURL

text = "Here is an image: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg== and some text."

contents = message_contents_from_text(text)

print(contents[0])
# Here is an image:

assert isinstance(contents[1], DataURL)
print(contents[1].mime_type)
# image/png

print(contents[2])
# and some text.
```

## Development

To install the development dependencies, run:

```bash
pip install -r requirements-all.txt
```

To run the tests, run:

```bash
pytest
```

## License

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

