ao3fetch
A typed Python 3.12+ library for scraping Archive of Our Own (AO3) and AO3-compatible OTW archives (such as Superlove or SquidgeWorld), ported from FujoWebDev/AO3.js. (Currently up-to-date with Commit 62e3ab8e.)
Features
- Works & Chapters: Fetch work metadata (
getWork), full work or single-chapter HTML/notes (getWorkContent), and/navigatechapter indices with publication dates (getWorkWithChapters). - Series, Users & Tags: Scrape series metadata & work blurbs (
getSeries), user profiles & public works (getUser,getUserWorks), tag wrangling/hierarchies (getTag,getTagNameById), and tag search (searchTags). - Pagination: Iterate or collect multi-page results with
getAllPagesandcollectAllPages. - EPUB Downloads: Parse downloaded AO3
.epubfiles offline withparseEpubWork(extracting metadata, chapters, notes, and embedded images). - Text & Markdown Conversion: Convert AO3 HTML prose/notes to plain text (
toPlainText) or clean CommonMark Markdown (toMarkdown). - Archive-Agnostic: Target any OTW/AO3-compatible archive via
setArchiveBaseUrl(...)or theARCHIVE_BASE_URLenvironment variable. - Pluggable Fetcher: Swap the HTTP layer (
setFetcher), wrap with429 Retry-After+5xxretry backoff (withRetry), and add in-memory LRU+TTL caching (withCache). - Fully Typed: Ships with
py.typed(PEP 561) and slotted dataclasses.
Installation
pip install ao3fetch
Requires Python 3.12+ and beautifulsoup4>=4.12.
Quick Start
import ao3fetch
# Optional: enable retry (respecting 429 Retry-After) and in-memory caching.
ao3fetch.setFetcher(ao3fetch.withCache(ao3fetch.withRetry(ao3fetch.defaultFetch)))
# Fetch a full work from AO3 (or another AO3-compatible archive).
work = ao3fetch.getWorkContent(123456, fullWork=True)
if not isinstance(work, ao3fetch.LockedWorkSummary):
print(work.title, "by", ", ".join(a.pseud for a in work.authors))
for chapter in work.content.chapters:
markdown = ao3fetch.toMarkdown(chapter.html)
print(markdown)
Targeting an AO3-Compatible Archive
import ao3fetch
ao3fetch.setArchiveBaseUrl("https://superlove.sayitditto.net")
work = ao3fetch.getWork(1269)
ao3fetch.resetArchiveBaseUrl()
Parsing a Local AO3 EPUB Download
from pathlib import Path
import ao3fetch
work = ao3fetch.parseEpubWork(Path("story.epub").read_bytes(), filePath="story.epub")
print(work.title, len(work.content.chapters))
Iterating Paginated Listings
import ao3fetch
for page in ao3fetch.getAllPages(ao3fetch.getSeries, seriesId=77):
for blurb in page.works:
print(blurb.title)
API Overview
See the full API Reference for complete type signatures, data class fields, enums, and behavioral notes.
| Category | Exports |
|---|---|
| Works & Chapters | getWork, getWorkContent, getWorkWithChapters, parseWorkBlurb |
| Series | getSeries |
| Users | getUser, getUserWorks |
| Tags | getTag, getTagNameById, searchTags |
| Downloads | parseEpubWork |
| Pagination | getAllPages, collectAllPages, PagedResult |
| HTML Conversion | toPlainText, toMarkdown |
| URLs & Base URL | DEFAULT_BASE_URL, setArchiveBaseUrl, getArchiveBaseUrl, resetArchiveBaseUrl, getWorkUrl, getWorkIndexUrl, getSeriesUrl, getAsShortUrl, getDownloadUrls, getUserProfileUrl, getUserWorksUrl, getTagUrl, getTagWorksFeedUrl, getTagWorksFeedAtomUrl, getUserDetailsFromUrl, getAuthorFromUrl, getWorkDetailsFromUrl, getSearchUrlFromTagFilters, isValidArchiveId, parseArchiveId |
| Fetcher & Middleware | defaultFetch, getFetcher, setFetcher, resetFetcher, withRetry, withCache, getRetryAfterSeconds, FetchResponse, Fetcher, RetryEvent, OnRetryCallback |
| Errors | InvalidIDError, ArchivePageRequestError |
| Entities & Enums | WorkSummary, WorkWithText, LockedWorkSummary, WorkWithChapters, DownloadedWork, Series, User, UserWorks, Tag, TagSearchResultSummary, Author, Chapter, ChapterText, WorkRatings, WorkCategory, WorkWarnings, WorkWarningStatus, ... |
Development
pip install -r requirements-dev.txt
./lint # runs ruff, black, mypy, pylint (10/10), check-manifest, and pytest
See CONTRIBUTING.md for coding conventions.
License
MIT License — see LICENSE.md. Ported from FujoWebDev/AO3.js (MIT).
Metadata
Release files for ao3fetch 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ao3fetch-0.1.0.tar.gz | 52.7 kB | Without provenance | Details for ao3fetch-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ao3fetch-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for ao3fetch-0.1.0-py3-none-any.whl |
Total release size: 93.1 kB
Release files / ao3fetch-0.1.0.tar.gz
| Download URL | ao3fetch-0.1.0.tar.gz |
|---|---|
| Size | 52.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3c2a4057b279723444fd74f31d1221d32be18ff91389fd5a7a117b93fbb0beb8
|
|
BLAKE2b-256 checksum How to use checksums |
badebef4c14d0718d8deb2b488ba8fedb1cdaa5fab2463d4e6a2d618ac239cfa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.6
|
Release files / ao3fetch-0.1.0-py3-none-any.whl
| Download URL | ao3fetch-0.1.0-py3-none-any.whl |
|---|---|
| Size | 40.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
83c09ab8fca278b8186c3c273871f021b8600f6cd12c8cef88e2f08837fae38c
|
|
BLAKE2b-256 checksum How to use checksums |
a878269de2eeded119519ccd0e26567b0ad14a431e7febb2535e4df1f013d012
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.6
|
Security for ao3fetch 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.