DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk7 min

How to Build a FastAPI Service That Converts Articles to Markdown with Playwright

A practical design for turning article URLs into Markdown with FastAPI and Playwright, including browser cleanup, concurrency choices, readiness handling, and a benchmark plan.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Build the service as a bounded pipeline, not as a single browser call: validate the request, choose whether a browser is necessary, navigate and wait for a defined readiness condition, extract the article, convert it to Markdown, enforce limits, and close browser resources before returning a structured result. FastAPI can orchestrate asynchronous I/O; Playwright can render pages that need a browser. Neither project’s documentation establishes a throughput figure or article-extraction accuracy guarantee for this combined workload, so call the service “high-throughput” only after measuring it on representative pages and target hardware.

What the service needs to do

An article-to-Markdown API accepts a URL and returns the main readable content in a format that downstream language-model workflows can consume. Its work spans several stages with different failure modes: network access, browser execution, content identification, conversion, and response handling.

As an Amazon Associate I earn from qualifying purchases.

  1. Validate and normalize the submitted URL. Reject malformed input and enforce request-size and timeout limits. Validation is only one part of the security design for a service that fetches caller-supplied URLs.
  2. Choose a retrieval path. Fetch and parse server-returned HTML when that is sufficient; use a browser when the target depends on client-side rendering or browser behavior.
  3. Navigate and establish readiness. Wait for a bounded, page-appropriate condition rather than assuming that the browser’s load event means the article is ready.
  4. Identify the article content. Select the main text and any metadata the API intends to return. Treat extraction as its own component, with failures surfaced rather than silently returning navigation or unrelated page text.
  5. Convert the selected content to Markdown. Keep extraction and conversion separate so each can be evaluated and changed independently.
  6. Apply output and time limits, then clean up. Bound the work per request, close the page’s context, and return a defined success or error response.

FastAPI’s async guidance distinguishes I/O concurrency from CPU-bound parallel work. A request waiting on navigation is not the same bottleneck as a process spending CPU time extracting and converting a large document. Measure each stage before choosing how to scale it.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When should the API use Playwright?

Playwright is useful when the page must be rendered or interacted with in a browser before its useful content appears. It is not automatically required for every URL. A simpler fetch-and-parse route may suit pages whose article HTML is already present in the server response, while a browser route can handle pages that rely on client-side behavior. The official Playwright documentation describes browser navigation and pages, but does not establish which route is more accurate, cheaper, or faster for article extraction.

Decision factor Fetch and parse HTML Render with Playwright
Page compatibility Depends on whether the response contains usable article content. Can handle pages that require browser rendering or behavior.
JavaScript dependence Not suited to content that only appears after client-side execution. Can execute page behavior in a browser.
Resource use per job Measure on the chosen parser and page mix; no value is established here. Measure browser, page, and process costs on the chosen deployment; no value is established here.
Latency and failure modes Evaluate against representative targets and your timeout policy. Evaluate navigation, readiness, browser startup, and cleanup against representative targets.
Extraction quality Test the same representative corpus used to assess the browser route. Test the same representative corpus; rendering alone does not guarantee correct article extraction.

Do not assume a browser route improves extraction quality just because it renders a page. Compare both approaches using the same target pages and the same definition of a successful article extraction.

How should FastAPI handle concurrency?

Use async for awaitable I/O

When an endpoint calls asynchronous libraries using await, FastAPI’s guidance supports using async def. That lets the application handle other work while an operation is waiting on I/O. It does not make CPU-heavy extraction or Markdown conversion run in parallel automatically.

Separate CPU work from network waiting

Profile navigation, extraction, and conversion independently. If content processing proves CPU-bound, evaluate a separate process or worker strategy rather than expecting an asynchronous endpoint to remove that bottleneck. Keep the chosen approach tied to measured workload behavior.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Treat worker count as a deployment choice

FastAPI documents multiple worker processes as a way to use multiple CPU cores and handle more requests. More processes also require memory and introduce startup and process-management considerations. With browser automation, measure the combined API-and-browser footprint on the target platform; a worker count suitable for a lightweight JSON endpoint is not evidence of a suitable count for browser jobs.

FastAPI’s worker documentation describes the --workers option for running processes in parallel and taking advantage of multi-core CPUs. It does not prescribe a universal worker count for a service that launches or manages browser work.

How should Playwright browser resources be isolated and cleaned up?

In Playwright, a browser context represents an independent session, and pages live inside contexts. A context can contain multiple pages, but the Playwright documentation does not establish a safe universal number of parallel pages or recommend a particular pool size.

  • Create contexts explicitly when you need a clear boundary for per-job browser state.
  • Close contexts created with browser.new_context() before closing the browser, as the Playwright Browser documentation recommends.
  • Choose one page per job, multiple pages, or a bounded pool based on measurements and isolation needs—not on an assumed documentation limit.
  • Handle cancellation and request deadlines so a timed-out job does not leave browser resources running without bounds.

Playwright’s Python API is documented as not thread-safe. In a multithreaded design, follow Playwright’s guidance to use a Playwright instance per thread; do not treat an asynchronous API as permission to share Playwright objects arbitrarily across threads.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How should navigation decide that an article is ready?

A page’s load event may happen before useful content is available. Playwright notes that some pages continue lazy fetching or UI population after load. Define readiness in terms of the target page or a supported extraction condition, and keep the wait bounded with explicit timeout and error handling.

A long fixed sleep is a poor general readiness rule: it can waste time when a page is ready quickly and still fail when a page takes longer. Record readiness timeouts as a distinct failure so you can tell them apart from navigation errors and extraction failures.

What should the API return?

Define a stable response contract before implementation. For example, a successful response can contain the normalized source URL, extracted title when available, Markdown, and processing metadata. An error response should identify the failed stage in a machine-readable way without implying that a failed extraction produced valid article text. The exact fields and naming below are an implementation choice, not a FastAPI or Playwright-prescribed schema.

{
  "source_url": "https://example.com/article",
  "title": "Example article",
  "markdown": "# Example article\n\nArticle text...",
  "status": "ok"
}

Set explicit limits for request duration and output size. Decide how the API responds when a page times out, yields no article content, or exceeds a configured limit. Make partial or failed extraction distinguishable from a complete result rather than returning an empty Markdown string that looks successful.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What security work is required for public URL fetching?

Accepting arbitrary URLs makes outbound navigation a security boundary, not just an input-validation task. URL validation alone should not be presented as sufficient protection. The documentation reviewed for FastAPI and Playwright does not provide authoritative SSRF-prevention guidance for a public URL-fetching service. Before exposing one publicly, design and review protections for redirects, DNS rebinding, private-address access, and network egress using dedicated security guidance. Do not infer that browser isolation or a well-formed URL makes arbitrary outbound requests safe.

How can you establish whether it is high-throughput?

No validated requests-per-second, latency, extraction-accuracy, or memory-per-page figure is established for this exact FastAPI-and-Playwright service. Benchmark your implementation on its intended platform before publishing or relying on a capacity claim.

Record a reproducible workload

  • Hardware or container CPU and memory limits.
  • Browser engine and version.
  • A representative page mix, including pages with and without client-side rendering.
  • Concurrency, navigation and request timeouts, and any configured resource limits.
  • Success and error rates, output sizes, and latency percentiles.
  • The extraction success criteria and how results were checked.

Scale the measured bottleneck

If navigation dominates, investigate bounded I/O concurrency and the browser-resource lifecycle. If CPU-heavy extraction or conversion dominates, evaluate process-based work separately. If memory is the constraint, assess the combined browser and application footprint before increasing workers or parallel pages. Change one relevant limit at a time and rerun the same workload so the effect is measurable.

Implementation checklist

  • Choose a browser only when the target page needs rendering or browser behavior.
  • Use async endpoints for awaitable I/O, not as a substitute for CPU parallelism.
  • Make readiness conditions explicit and bounded.
  • Give each job a clear page and context lifecycle, including cleanup on errors and cancellation.
  • Respect Playwright’s thread-safety guidance.
  • Define output, time, and error behavior in the API contract.
  • Complete a dedicated outbound-request security design before offering arbitrary URL fetching publicly.
  • Use a workload-specific benchmark before describing capacity as high throughput.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.