diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 0000000..bc1b71f --- /dev/null +++ b/.github/workflows/docs.yml @@ -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 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..42a17c3 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/docs/api/ diff --git a/README.md b/README.md index 885864f..105d5c5 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..d84176d --- /dev/null +++ b/docs/README.md @@ -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 +``` diff --git a/docs/check_api_docs.py b/docs/check_api_docs.py new file mode 100644 index 0000000..b9a0f58 --- /dev/null +++ b/docs/check_api_docs.py @@ -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()) diff --git a/docs/requirements.txt b/docs/requirements.txt new file mode 100644 index 0000000..6fe7e96 --- /dev/null +++ b/docs/requirements.txt @@ -0,0 +1 @@ +pdoc==16.0.0 diff --git a/scripts/build_api_docs.sh b/scripts/build_api_docs.sh new file mode 100755 index 0000000..16024b3 --- /dev/null +++ b/scripts/build_api_docs.sh @@ -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