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

Uploaded Python 3

File details

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

File metadata

  • Download URL: markdown_new-0.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 78d4c54560bd0289b375a2cfddf1cffe4507ef275b472321775b68ec023798ce
MD5 a2901c9505380394def518c2f3fab470
BLAKE2b-256 91c0d6465e25c8b856b6342aba2f4b7937cacf53e51bbcb082901101ea2a170d

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: markdown_new-0.0.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 31027a9577d4c93cd72de880e31e2793ff8e4e3a7c816ebf48e4f01c1a1ed1c7
MD5 af99509f4e4d754b31aca6ef0a842fe7
BLAKE2b-256 06ffe19d2993f30b1a964d1cb066b6a53980090b4dfc8f8c7c95fb62dfede9cf

See more details on using hashes here.

Provenance

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