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.3.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.3-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: markdown_new-0.0.3.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.3.tar.gz
Algorithm Hash digest
SHA256 632bb2ef6286d8ce053e65209da59f3507519f7aaaf01f32efcf48a93ce3546f
MD5 7111594f6c752687a6b0b91a3f333f2c
BLAKE2b-256 fe517126cd96618065d40dd410e42b52f67256056495dc7c477f3a336a717810

See more details on using hashes here.

Provenance

The following attestation bundles were made for markdown_new-0.0.3.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.3-py3-none-any.whl.

File metadata

  • Download URL: markdown_new-0.0.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a495e27161b4f9da77db5c1d28ebe7eb4f3fd6f27833194cdaeac9fd298ce3e0
MD5 e710eb62acdebf8ae00615ffef4ccc3d
BLAKE2b-256 1bc765bc8ecca26b5aca43bbd9312f6aae4beccae33079e8de62d42b9d27e7ce

See more details on using hashes here.

Provenance

The following attestation bundles were made for markdown_new-0.0.3-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