Skip to main content

Python client library for markdown.new URL-to-Markdown conversion

Project description

markdown-new

PyPI - Version PyPI - Python Version License

Python client for markdown.new, a Cloudflare-backed service that converts web URLs into Markdown.

Table of contents

What the project does

markdown-new is a lightweight, production-oriented Python client for the public markdown.new conversion endpoint. It handles:

  • URL normalization for request-path-based conversions
  • Synchronous and asynchronous HTTP client workflows
  • Typed request/response handling
  • Consistent error mapping for service failures
  • Optional authentication header customization
  • Lightweight markdown token metadata extraction when present

Why this project is useful

  • Fast integration: one method call to convert a URL into Markdown.
  • Reliable transport options: supports both blocking and asyncio usage.
  • Built-in validation: validates URL inputs (scheme + host) before the network call.
  • Predictable error handling: clear exception classes for URL, authentication, rate limit, conversion, and transport failures.
  • Type-aware: py.typed marker and explicit response model for IDE-friendly development.
  • Practical ergonomics: context managers and batch helpers are included for both client types.

Get started

Installation

Install from PyPI:

pip install markdown-new

Install with development dependencies:

pip install -e ".[dev]"

Quick start (sync)

from markdown_new import MarkdownNewClient

with MarkdownNewClient() as client:
    result = client.convert("https://example.com")

print(result.markdown)
print(result.requested_url)
print(result.status_code)

Quick start (async)

import asyncio
from markdown_new import AsyncMarkdownNewClient


async def main() -> None:
    async with AsyncMarkdownNewClient() as client:
        result = await client.convert("https://example.com")
    print(result.markdown)
    print(result.requested_url)


asyncio.run(main())

Batch conversion

from markdown_new import MarkdownNewClient, AsyncMarkdownNewClient

urls = [
    "https://example.com",
    "https://blog.cloudflare.com/markdown-for-agents/",
]

with MarkdownNewClient() as client:
    sync_results = client.convert_many(urls)
    for item in sync_results:
        print(item.requested_url, "->", len(item.markdown), "chars")

async def batch():
    async with AsyncMarkdownNewClient() as client:
        async_results = await client.convert_many(urls, concurrency=5)
    for item in async_results:
        print(item.requested_url, "tokens", item.markdown_tokens)

Configuration and usage patterns

markdown.new expects the URL as part of the request path, which means query strings and fragments are encoded by the client automatically.

You can customize request identity and authentication headers with optional client arguments:

from markdown_new import MarkdownNewClient

client = MarkdownNewClient(
    api_key="YOUR_API_KEY",
    api_key_header="Authorization",
    api_key_prefix="Bearer",
    user_agent="my-service/1.0",
    headers={"Accept-Language": "en-US"},
)

HTTP behavior and URL handling

  • Supported URL schemes: http and https
  • The client normalizes and URL-encodes target paths for you.
  • Timeout is configurable per call or per client instance.
  • Batch conversions use the input order.

Response and errors

Successful calls return MarkdownResponse:

  • markdown: converted Markdown payload
  • requested_url: original URL passed by the caller
  • normalized_url: encoded target URL sent to the service
  • status_code: HTTP status code
  • content_type: normalized response media type
  • markdown_tokens: optional token usage metadata from response headers
  • headers: response headers map

Errors are expressed through:

  • MarkdownNewInvalidURLError for malformed input
  • MarkdownNewConversionError for API-level conversion problems
  • MarkdownNewAuthenticationError for 401/403 responses
  • MarkdownNewRateLimitError for 429 responses
  • MarkdownNewHTTPError for other unexpected non-success HTTP errors
  • MarkdownNewRequestError for transport and unexpected client issues

Testing

Run unit tests:

pytest

Run live conversion tests against the network endpoint:

pytest -m integration

Recommended local quality gate:

ruff check .
ruff format .
black --check .

If you installed pre-commit, you can run:

pre-commit install
pre-commit run --all-files

Project help

Maintainers and contributing

Maintainer:

  • Dave Lindon — dave@knowledge2.ai

Contributions are welcome:

  • Open an issue for bugs, feature requests, or API questions.
  • Open a pull request for improvements or fixes.
  • See CONTRIBUTING.md for full contribution guidelines.
  • Prefer MarkdownNewClient and AsyncMarkdownNewClient changes to include tests in tests/.

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

markdown_new-0.0.1.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

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

markdown_new-0.0.1-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file markdown_new-0.0.1.tar.gz.

File metadata

  • Download URL: markdown_new-0.0.1.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for markdown_new-0.0.1.tar.gz
Algorithm Hash digest
SHA256 13b63b3203db17fa6836c98a5cb9cb3936384ebdaeb6dc9bceb70d5ad8a9b25e
MD5 96ed5aad76cfc0931684403d217b10f2
BLAKE2b-256 2d625fd4b79574d36256216bd7989efc4db084b3bb9fa63a1737164a2d93cd2a

See more details on using hashes here.

Provenance

The following attestation bundles were made for markdown_new-0.0.1.tar.gz:

Publisher: publish.yml on davelindo/markdown-new-python-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file markdown_new-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: markdown_new-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 10.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for markdown_new-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b8c5e64ef551ffbd8a9b8cccbf2291e8e49d0aa67985653920732e44c5d9f7cb
MD5 aead41e0f289cdf368e48aaad2dac632
BLAKE2b-256 337b283315a37cb54c76c8f5b853b10c7291ab6219288bb3ce33ae2f81334c80

See more details on using hashes here.

Provenance

The following attestation bundles were made for markdown_new-0.0.1-py3-none-any.whl:

Publisher: publish.yml on davelindo/markdown-new-python-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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