# Python SDK

> Create projects, batch-render revisions, and switch styles programmatically from Python with the aifilm package.

Everything the `aifilm` CLI does is also exposed as a clean, minimal Python API so you can automate batch renders, multi-style comparisons, or CI video generation.

## Basic Example

```python
from aifilm import FilmError, __version__, new_project, render

print("Using aifilm", __version__)

# 1. Create a portable starter project
film_path = new_project("greeting")

# 2. Render a fast preview MP4
mp4_path = render(film_path, "greeting.mp4")
print("Rendered:", mp4_path)
```

## Render All 6 Built-In Styles in a Loop

```python
from aifilm import render

STYLES = [
    "studio_ink",
    "realistic",
    "clean_vector",
    "storybook_watercolor",
    "riso_print",
    "blueprint_ink",
]

for style in STYLES:
    out = render(
        "greeting/film.yaml",
        f"out/greeting-{style}.mp4",
        style=style,
        overwrite=True,
    )
    print(f"{style}: {out}")
```

## Full-HD Final Export with Error Handling

```python
from aifilm import FilmError, render

try:
    render(
        "greeting/film.yaml",
        "greeting-hd.mp4",
        edit="cut",
        style="realistic",
        final=True,
        overwrite=True,
    )
except FilmError as err:
    print("Render stopped safely:", err)
```

## API Summary

| Symbol | Signature / Description |
|---|---|
| `__version__` | Installed `aifilm` version string (e.g. `"0.1.0"`) |
| `new_project(directory)` | Creates `<directory>/film.yaml` and `<directory>/film.schema.json`, returning the path to `film.yaml` |
| `render(film, out, *, edit="cut", style=None, final=False, overwrite=False)` | Renders an H.264 MP4 in an isolated worker process and returns the output `Path` |
| `FilmError` | Exception raised on YAML validation errors, failed `--final` quality checks, or protected existing outputs |

> **Isolation guarantee:** `render()` executes Chromium and engine plugins in a short-lived worker subprocess so your calling Python process stays clean and safe for concurrent jobs.

## Related pages

- [Make & Revise Your First Film](https://film.praison.ai/docs/getting-started/first-film.md)
- [CLI Command Reference](https://film.praison.ai/docs/guides/cli-reference.md)
- [Client & Studio Revision Workflow](https://film.praison.ai/docs/guides/studio-revisions.md)
