Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Python API reference

on:
push:
branches: ["master"]
pull_request:
branches: ["master"]
workflow_dispatch:

permissions:
contents: read

# One Pages deployment at a time; a newer push waits rather than cancelling one
# that is mid-deploy.
concurrency:
group: pages-${{ github.ref }}
cancel-in-progress: false

jobs:
docs:
name: Build Python API reference
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.12"
- name: Install SDK and documentation tools
run: python -m pip install -e . -r docs/requirements.txt
- name: Build API reference
run: scripts/build_api_docs.sh
- name: Check public API pages
run: python docs/check_api_docs.py
- name: Upload API reference
uses: actions/upload-artifact@v4
with:
name: python-api-reference
path: docs/api/
if-no-files-found: error
- name: Upload Pages artifact
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/master'
uses: actions/upload-pages-artifact@v3
with:
path: docs/api/

deploy:
name: Deploy to GitHub Pages
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/master'
needs: docs
runs-on: ubuntu-latest
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy
id: deployment
uses: actions/deploy-pages@v4
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/docs/api/
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ See [Coding agent prompts](https://www.assemblyai.com/docs/coding-agent-prompts)

Visit our [AssemblyAI API Documentation](https://www.assemblyai.com/docs) to get an overview of our models!

Browse the public classes and methods in the [Python SDK API reference](https://assemblyai.github.io/assemblyai-python-sdk/).

# Quick Start

## Installation
Expand Down
18 changes: 18 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Python SDK API reference

The API reference uses public module docstrings and type annotations. It is published at https://assemblyai.github.io/assemblyai-python-sdk/ on every push to `master`.

To build it locally, use Python 3.12. Create and activate a virtual environment. Then install the SDK and the documentation tool:

```bash
python3.12 -m venv /tmp/assemblyai-sdk-docs
source /tmp/assemblyai-sdk-docs/bin/activate
python -m pip install -e . -r docs/requirements.txt
scripts/build_api_docs.sh
```

The script writes the HTML files to `docs/api/`. Check that the public API is present:

```bash
python docs/check_api_docs.py
```
74 changes: 74 additions & 0 deletions docs/check_api_docs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"""
Checks the built API reference in `docs/api/` for the public SDK surface.

Run it after `scripts/build_api_docs.sh`. It lives outside `tests/` because it
needs the built reference, which the regular test run does not build.
"""

import sys
from pathlib import Path

API_DOCS = Path(__file__).parent / "api"

# One page per documented module. The top-level `assemblyai` page re-exports
# most public names, so a module dropped from the build is only caught here.
MODULE_PAGES = (
"assemblyai.html",
"assemblyai/prerecorded/v2.html",
"assemblyai/sync/v1.html",
"assemblyai/dictation/v1.html",
"assemblyai/llm_gateway/v1.html",
"assemblyai/streaming/v3.html",
"assemblyai/tts/v1.html",
)

PUBLIC_NAMES = (
"Transcriber",
"SyncTranscriber",
"DictationTranscriber",
"LLMGateway",
"RealTimeTranscriber",
"TTSSession",
)

PUBLIC_MEMBERS = (
"Transcriber.transcribe",
"SyncTranscriber.transcribe",
"DictationTranscriber.transcribe_live",
"LLMGateway.chat",
"RealTimeTranscriber.stream",
"TTSSession.speak",
)


def main() -> int:
html_files = list(API_DOCS.rglob("*.html"))
if not html_files:
print("No API reference found: run scripts/build_api_docs.sh first")
return 1

reference = "\n".join(path.read_text(encoding="utf-8") for path in html_files)

problems = [
f"missing page {page}"
for page in MODULE_PAGES
if not (API_DOCS / page).is_file()
]
problems += [f"missing {name}" for name in PUBLIC_NAMES if name not in reference]
problems += [
f"missing {member}"
for member in PUBLIC_MEMBERS
if f'id="{member}"' not in reference
]
if "assemblyai._audio" in reference or "_audio.html" in reference:
problems.append("the internal assemblyai._audio module is documented")

for problem in problems:
print(problem)
if not problems:
print(f"API reference OK ({len(html_files)} pages)")
return 1 if problems else 0


if __name__ == "__main__":
sys.exit(main())
1 change: 1 addition & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pdoc==16.0.0
12 changes: 12 additions & 0 deletions scripts/build_api_docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -euo pipefail

export PYTHONWARNINGS=error

pdoc -o docs/api \
assemblyai \
assemblyai.prerecorded.v2 \
assemblyai.sync.v1 \
assemblyai.dictation.v1 \
assemblyai.llm_gateway.v1 \
assemblyai.tts.v1
Loading