aianim Package¶
Top-Level Exports (aianim)¶
aianim: AI agentic studio combining handanim drawing and voiceanim speech into video creation.
- class aianim.ScenePlan(title, description='', total_duration=0.0, width=1920, height=1088, scenes=<factory>)[source]
Bases:
objectComplete structured plan for a multi-scene handanim animation.
- Parameters:
- title: str
- description: str = ''
- total_duration: float = 0.0
- width: int = 1920
- height: int = 1088
- classmethod from_json(json_str)[source]
Parse from JSON string, handling optional markdown fence wrapping.
- validate()[source]
Validate structure and return list of validation warning/error messages.
- class aianim.SceneSpec(id=1, title='', duration=5.0, drawables=<factory>, animations=<factory>)[source]
Bases:
objectSpecification for an individual scene segment.
- Parameters:
title (str)
duration (float)
drawables (list[DrawableSpec])
animations (list[AnimationSpec])
- title: str = ''
- duration: float = 5.0
- drawables: list[DrawableSpec]
- animations: list[AnimationSpec]
- class aianim.DrawableSpec(id, type, params=<factory>, styles=<factory>)[source]
Bases:
objectSpecification for a visual shape or element.
- id: str
- type: str
- classmethod from_dict(data)[source]
- Parameters:
- Return type:
- class aianim.AnimationSpec(drawable_id, type, start_time=0.0, duration=1.0, params=<factory>)[source]
Bases:
objectSpecification for an animation applied to a drawable.
- Parameters:
- drawable_id: str
- type: str
- start_time: float = 0.0
- duration: float = 1.0
- classmethod from_dict(data)[source]
- Parameters:
- Return type:
- aianim.plan_to_python(plan, output_path='output.mp4')[source]
Compile a structured ScenePlan into canonical handanim Python code.
- aianim.check_code(code_str)[source]
Run static AST analysis on handanim Python code.
- Parameters:
code_str (str) – Source code string to inspect.
- Returns:
DiagnosticReport with validity flag, errors, warnings, and suggestions.
- Return type:
- class aianim.DiagnosticReport(is_valid, errors=<factory>, warnings=<factory>, suggestions=<factory>)[source]
Bases:
objectDiagnostic outcome containing syntax and semantic linter warnings/errors.
- is_valid: bool
- class aianim.InteractiveSession(model=None, verbose=True, output_dir='.')[source]
Bases:
objectConversational CLI session with live inspection and arrow-key user feedback.
- Parameters:
model (BaseLLMModel | None)
verbose (bool)
output_dir (str)
- log(tag, message, color='\x1b[94m')[source]
Print formatted stage log.
- log_prompt(system_message, user_message)[source]
Print under-the-hood prompt when verbose mode is active.
- prompt_choice(message, choices, default=None)[source]
Prompt user with an interactive arrow-key choice menu using questionary with fallback.
- prompt_text(message, default='')[source]
Prompt for text input using questionary or standard input.
- run()[source]
Run the interactive session.
- handle_topic_turn(topic)[source]
Analyze topic, ask clarifying questions if ambiguous, or draft plan.
- Parameters:
topic (str)
- handle_user_message(message)[source]
Handle iterative conversational user feedback.
- Parameters:
message (str)
- generate_and_review_plan(topic_summary)[source]
Run Ideation stage, display plan, and provide interactive arrow-key choice menu.
- Parameters:
topic_summary (str)
- refine_plan(feedback)[source]
Ask the model to update the current ScenePlan based on user feedback.
- Parameters:
feedback (str)
- display_plan_summary(plan)[source]
Format and print an attractive summary of the plan using rich tree/panels or ANSI.
- Parameters:
plan (ScenePlan)
- generate_code_from_plan()[source]
Compile plan into Python and execute.
- execute_and_verify(code, output_path)[source]
Run code in subprocess and report live results.
- class aianim.AnimationGenerator(model=None, prompt_manager=None, executor=None, prompt_version='v1')[source]
Bases:
objectOrchestrates topic ideation, code generation, execution, and self-correction.
- Parameters:
model (BaseLLMModel | None)
prompt_manager (PromptManager | None)
executor (CodeExecutor | None)
prompt_version (str)
- generate(topic, output_path='output.mp4', max_retries=2, use_compiler=False)[source]
Run end-to-end animation generation pipeline with self-correction feedback loop.
- Parameters:
topic (str) – Natural language topic description (e.g. ‘explain Pythagorean theorem’).
output_path (str) – Target video or image output path.
max_retries (int) – Maximum self-correction attempts upon syntax or execution failure.
use_compiler (bool) – If True, compiles the ScenePlan directly using plan_to_python() instead of calling the LLM codegen prompt.
- Returns:
PipelineResult containing generated code, plan, and execution status.
- Return type:
- class aianim.PipelineResult(success, code, scene_plan, output_path, retries_used, execution_result, error='')[source]
Bases:
objectOutcome of the animation generation pipeline.
- Parameters:
- success: bool
- code: str
- output_path: str
- retries_used: int
- execution_result: ExecutionResult | None
- error: str = ''
- class aianim.CodeExecutor(default_timeout=45.0)[source]
Bases:
objectExecutes generated Python code in an isolated subprocess.
- Parameters:
default_timeout (float)
- execute(code, expected_output=None, timeout=None, working_dir=None)[source]
Execute Python code string in a subprocess and verify output creation.
- Parameters:
code (str) – Full Python source code.
expected_output (str | None) – Optional path to output media file (e.g. .mp4, .svg) to verify.
timeout (float | None) – Subprocess timeout in seconds. Defaults to self.default_timeout.
working_dir (str | Path | None) – Working directory for execution. Defaults to repository root.
- Returns:
ExecutionResult containing execution status, logs, and error details.
- Return type:
- class aianim.ExecutionResult(success, stdout, stderr, returncode, output_exists, execution_time, error_summary='')[source]
Bases:
objectOutcome of running a generated handanim script.
- Parameters:
- success: bool
- stdout: str
- stderr: str
- returncode: int
- output_exists: bool
- execution_time: float
- error_summary: str = ''
- class aianim.BaseLLMModel[source]
Bases:
ABCAbstract base class for LLM providers.
- abstractmethod invoke(messages, system_message=None, response_format=None)[source]
Invoke the LLM with messages and optional system message/response format.
- Parameters:
- Returns:
The generated text response string.
- Return type:
- class aianim.BedrockModel(model_id=None, region_name=None, profile_name=None, client=None)[source]
Bases:
BaseLLMModelAWS Bedrock model provider using the unified Bedrock Converse API.
Supports Claude 3.5 Sonnet, Nova, Llama 3, and any model hosted on Bedrock.
- DEFAULT_MODEL_ID = 'anthropic.claude-3-5-sonnet-20241022-v2:0'
- __init__(model_id=None, region_name=None, profile_name=None, client=None)[source]
Initialize AWS Bedrock client.
- class aianim.OpenRouterModel(model_name='anthropic/claude-3.5-sonnet', api_key=None)[source]
Bases:
BaseLLMModelOpenRouter LLM provider for OpenAI-compatible completions.
- BASE_URL = 'https://openrouter.ai/api/v1/chat/completions'
- invoke(messages, system_message=None, response_format=None)[source]
Invoke the LLM with messages and optional system message/response format.
- Parameters:
- Returns:
The generated text response string.
- Return type:
- class aianim.MockModel(responses=None, response_fn=None)[source]
Bases:
BaseLLMModelDeterministic mock model for testing and offline runs.
- Parameters:
- invoke(messages, system_message=None, response_format=None)[source]
Invoke the LLM with messages and optional system message/response format.
- Parameters:
- Returns:
The generated text response string.
- Return type:
- aianim.get_model(provider=None, model_name=None, **kwargs)[source]
Factory to instantiate the appropriate LLM provider.
Resolution order: 1. Explicit provider argument (‘bedrock’, ‘openrouter’, ‘mock’). 2. Environment variable HANDANIM_AI_PROVIDER. 3. If AWS credentials exist, defaults to Bedrock. 4. If OPENROUTER_API_KEY exists, defaults to OpenRouter. 5. Fallback to MockModel.
- Parameters:
- Return type:
- class aianim.PromptManager(prompts_dir=None)[source]
Bases:
objectManages prompt template loading and version discovery.
- Parameters:
prompts_dir (Path | None)
- get(name, version='v1')[source]
Load a prompt template by name and version (e.g. name=’big_picture’, version=’v1’).
- aianim.get_available_assets()[source]
Scan and return available fonts, colors, and asset files.
- aianim.format_assets_markdown()[source]
Format available assets as clean Markdown for prompt injection.
- Return type:
aianim.schema¶
Structured scene representation and validation schema for AI-assisted animation.
- class aianim.schema.DrawableSpec(id, type, params=<factory>, styles=<factory>)[source]¶
Bases:
objectSpecification for a visual shape or element.
- class aianim.schema.AnimationSpec(drawable_id, type, start_time=0.0, duration=1.0, params=<factory>)[source]¶
Bases:
objectSpecification for an animation applied to a drawable.
- Parameters:
- class aianim.schema.SceneSpec(id=1, title='', duration=5.0, drawables=<factory>, animations=<factory>)[source]¶
Bases:
objectSpecification for an individual scene segment.
- Parameters:
title (str)
duration (float)
drawables (list[DrawableSpec])
animations (list[AnimationSpec])
- drawables: list[DrawableSpec]¶
- animations: list[AnimationSpec]¶
- class aianim.schema.ScenePlan(title, description='', total_duration=0.0, width=1920, height=1088, scenes=<factory>)[source]¶
Bases:
objectComplete structured plan for a multi-scene handanim animation.
- Parameters:
- classmethod from_json(json_str)[source]¶
Parse from JSON string, handling optional markdown fence wrapping.
aianim.compiler¶
Deterministic compiler: translates a structured ScenePlan into clean, executable Python code.
aianim.pipeline¶
Autonomous animation generation pipeline with self-correction feedback loop.
- class aianim.pipeline.PipelineResult(success, code, scene_plan, output_path, retries_used, execution_result, error='')[source]¶
Bases:
objectOutcome of the animation generation pipeline.
- Parameters:
- execution_result: ExecutionResult | None¶
- class aianim.pipeline.AnimationGenerator(model=None, prompt_manager=None, executor=None, prompt_version='v1')[source]¶
Bases:
objectOrchestrates topic ideation, code generation, execution, and self-correction.
- Parameters:
model (BaseLLMModel | None)
prompt_manager (PromptManager | None)
executor (CodeExecutor | None)
prompt_version (str)
- generate(topic, output_path='output.mp4', max_retries=2, use_compiler=False)[source]¶
Run end-to-end animation generation pipeline with self-correction feedback loop.
- Parameters:
topic (str) – Natural language topic description (e.g. ‘explain Pythagorean theorem’).
output_path (str) – Target video or image output path.
max_retries (int) – Maximum self-correction attempts upon syntax or execution failure.
use_compiler (bool) – If True, compiles the ScenePlan directly using plan_to_python() instead of calling the LLM codegen prompt.
- Returns:
PipelineResult containing generated code, plan, and execution status.
- Return type:
aianim.diagnostics¶
AST guardrails and code linter for agentic workflows and AI-generated scripts.
- class aianim.diagnostics.DiagnosticReport(is_valid, errors=<factory>, warnings=<factory>, suggestions=<factory>)[source]¶
Bases:
objectDiagnostic outcome containing syntax and semantic linter warnings/errors.
- class aianim.diagnostics.HandanimCodeAuditor[source]¶
Bases:
NodeVisitorAST visitor inspecting handanim-specific coding patterns and anti-patterns.
- IMMUTABLE_TRANSFORMS = {'rotate', 'scale', 'translate'}¶
- visit_ImportFrom(node)[source]¶
- Parameters:
node (ImportFrom)
aianim.executor¶
Subprocess execution engine with timeout and error capture for generated animations.
- class aianim.executor.ExecutionResult(success, stdout, stderr, returncode, output_exists, execution_time, error_summary='')[source]¶
Bases:
objectOutcome of running a generated handanim script.
- Parameters:
- class aianim.executor.CodeExecutor(default_timeout=45.0)[source]¶
Bases:
objectExecutes generated Python code in an isolated subprocess.
- Parameters:
default_timeout (float)
- execute(code, expected_output=None, timeout=None, working_dir=None)[source]¶
Execute Python code string in a subprocess and verify output creation.
- Parameters:
code (str) – Full Python source code.
expected_output (str | None) – Optional path to output media file (e.g. .mp4, .svg) to verify.
timeout (float | None) – Subprocess timeout in seconds. Defaults to self.default_timeout.
working_dir (str | Path | None) – Working directory for execution. Defaults to repository root.
- Returns:
ExecutionResult containing execution status, logs, and error details.
- Return type:
aianim.models¶
Multi-provider LLM interface supporting AWS Bedrock, OpenRouter, and Mock providers.
- class aianim.models.BaseLLMModel[source]¶
Bases:
ABCAbstract base class for LLM providers.
- class aianim.models.BedrockModel(model_id=None, region_name=None, profile_name=None, client=None)[source]¶
Bases:
BaseLLMModelAWS Bedrock model provider using the unified Bedrock Converse API.
Supports Claude 3.5 Sonnet, Nova, Llama 3, and any model hosted on Bedrock.
- DEFAULT_MODEL_ID = 'anthropic.claude-3-5-sonnet-20241022-v2:0'¶
- class aianim.models.OpenRouterModel(model_name='anthropic/claude-3.5-sonnet', api_key=None)[source]¶
Bases:
BaseLLMModelOpenRouter LLM provider for OpenAI-compatible completions.
- BASE_URL = 'https://openrouter.ai/api/v1/chat/completions'¶
- class aianim.models.MockModel(responses=None, response_fn=None)[source]¶
Bases:
BaseLLMModelDeterministic mock model for testing and offline runs.
- Parameters:
- aianim.models.get_model(provider=None, model_name=None, **kwargs)[source]¶
Factory to instantiate the appropriate LLM provider.
Resolution order: 1. Explicit provider argument (‘bedrock’, ‘openrouter’, ‘mock’). 2. Environment variable HANDANIM_AI_PROVIDER. 3. If AWS credentials exist, defaults to Bedrock. 4. If OPENROUTER_API_KEY exists, defaults to OpenRouter. 5. Fallback to MockModel.
- Parameters:
- Return type:
aianim.assets¶
Dynamic asset discovery and environment inspection for AI prompts and agents.
aianim.mcp_server¶
Model Context Protocol (MCP) server for handanim.
Enables Claude Code, Claude Desktop, Cursor, and Gemini to natively inspect, lint, compile, snapshot, and generate handanim whiteboard animations.
aianim.cli¶
Simplified CLI for aianim.
Two primary modes:
Interactive Assistant: For human users with AWS Bedrock seeking full control and visibility. Usage:
aianim(orhandanim-ai)MCP Server: For agentic systems (Claude Desktop, Claude Code, Cursor, Gemini) to generate, inspect, and see animations directly. Usage:
aianim mcp