Skip to main content

Official Python SDK for AutoLecture (https://autolecture.ai). Generate explainer videos from script or audio via a clean HTTP client.

Project description

autolecture — Python SDK

Official Python SDK for AutoLecture — author explainer videos as a .tex source, render them on the server, download an mp4. The SDK wraps the v2 HTTP API end-to-end: projects, assets, tex source, compile jobs (with polling), final-video download, voice clone, billing-adjacent reads.

The SDK is the supported way to drive AutoLecture from outside the web UI — built for CLIs, Claude Code skills, and any service-to-service use case where a JWT login flow doesn't fit.

Install

pip install autolecture

Python 3.10+. The SDK depends only on httpx>=0.27.

Auth

Every call needs an API key. To mint one:

  1. Sign in at https://autolecture.ai.
  2. Open https://autolecture.ai/account, find the API Keys section.
  3. Click Generate — copy the al_live_… string immediately, it's only shown once.

Pass it to the Client constructor (or read from AUTOLECTURE_API_KEY env var in your own code — the SDK doesn't read env vars itself, that's caller-side).

Quickstart

from pathlib import Path
from autolecture import Client

with Client(api_key="al_live_…") as al:
    # 1. Create a project.
    project = al.create_project(name="My first AutoLecture video")
    pid = project["id"]

    # 2. Upload a script + any assets you want to reference.
    al.upload_asset(pid, Path("./recording.mp3"))

    # 3. Write the VideoTeX source. See https://autolecture.ai/docs/dsl.
    al.put_tex(pid, "main.tex", r"""
        \title{Demo}
        \aspect{16:9}
        \begin{videotex}
            \begin{view}
                \say{Hello, AutoLecture!}
                \image[engine=gemini]{a duck explaining a concept on a chalkboard}
            \end{view}
        \end{videotex}
    """.strip())

    # 4. Compile. `compile()` blocks until the job terminates;
    #    `on_progress` fires after each poll for progress UI.
    job = al.compile(
        pid,
        on_progress=lambda j: print(f"  [{j['blocks_done']}/{j['blocks_total'] or '?'}] {j['status']}"),
    )
    print(f"Compile finished — {job['actual_cost_credits']} ✦ spent")

    # 5. Download the final mp4.
    al.download_preview(pid, dest="./out.mp4")
    print("Saved to ./out.mp4")

Errors

Every SDK exception inherits from AutoLectureError. The common subclasses carry the backend's structured-error fields as attributes:

from autolecture import (
    AutoLectureError, AuthenticationError, PermissionError,
    QuotaExceededError, InsufficientCreditsError, RateLimitError,
    CompileFailedError, NotFoundError, APIError,
)

try:
    al.compile(pid)
except InsufficientCreditsError as e:
    print(f"Need {e.shortfall} more ✦. Balance: {e.balance}, needed: {e.needed}")
except QuotaExceededError as e:
    print(f"Plan {e.plan} caps at {e.limit} projects (you have {e.used}).")
except CompileFailedError as e:
    print(f"Render failed:\n{e.error_log}")
except AutoLectureError as e:
    # Catch-all — every SDK error inherits from this.
    print(f"[{e.code}] {e.message}")

For a less specific error (e.g. an HTTP status we don't have a subclass for yet), you get a generic APIError with .status_code and .code.

What's in Client

Area Methods
Projects list_projects / create_project / create_project_from_zip / get_project / update_project / delete_project / archive_project / unarchive_project / duplicate_project
Tex source get_tex / put_tex
Assets upload_asset / list_assets / delete_asset
Compile compile (high-level + polling) / start_compile / get_compile_job / cancel_compile
Preview download_preview / download_block_preview
Voice clone upload_voice_sample / get_voice_sample / delete_voice_sample
Account get_balance / get_quota / get_usage
API key mint_api_key / get_api_key_status / revoke_api_key

See the docstrings — every public method maps 1:1 to a documented HTTP endpoint at https://autolecture.ai/api/v2/....

Pointing at a different server

Most users won't need this. For local development or staging:

al = Client(api_key="al_live_…", base_url="https://dev.autolecture.ai")
# or
al = Client(api_key="al_live_…", base_url="http://localhost:8000")

Async?

v0.1 is sync-only — httpx.Client, no await. An async variant (AsyncClient) is on the roadmap for v0.2 if there's demand; the typical "script in a Claude Code skill" use case is sync-friendly, so async hasn't been a priority.

Development

git clone https://github.com/scao7/autolecture-python
cd autolecture-python
pip install -e ".[dev]"
pytest -q
ruff check src tests
mypy src

Tests use respx to mock the backend HTTP — nothing reaches the network.

License

MIT — see LICENSE.

Links

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

autolecture-0.1.0.tar.gz (19.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

autolecture-0.1.0-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

Details for the file autolecture-0.1.0.tar.gz.

File metadata

  • Download URL: autolecture-0.1.0.tar.gz
  • Upload date:
  • Size: 19.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for autolecture-0.1.0.tar.gz
Algorithm Hash digest
SHA256 83d981771a5871962f2586dde864c5c90e03739ebd201826b39469811881e351
MD5 acd531485bff71c5975b73ba9a744293
BLAKE2b-256 d2e40e7b5fd2fb99ba7dcfd7a9a3602819a1b105f838512ec47c8afc3eea5cdb

See more details on using hashes here.

File details

Details for the file autolecture-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: autolecture-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 18.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for autolecture-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 66e661cfe35f2dcea289900a04c6b1a5aea90eb5ee1605249f4fd81421913071
MD5 39206e629b8638fa125f08b0bc103bef
BLAKE2b-256 a7a7959952b49bb5d0e0af7c91c3a7ccca4ccd1509cbd5f55a5d8111a506fa9e

See more details on using hashes here.

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