Skip to main content

Deterministic State-Driven Interactive Narrative Engine SDK

Project description

🚀 Story Builder Engine

Deterministic State-Driven Interactive Narrative Engine for Python Developers

Story Builder is a framework-agnostic Python SDK that provides a deterministic, state-driven engine for executing branching narratives with built-in validation and performance tracking.

Unlike "vibes-based" AI wrappers, Story Builder provides a rigorous mathematical model for story traversal, ensuring logical consistency and reliable state management.


🏗 Key Features

  • Deterministic Execution: No AI hallucinations in your core story logic.
  • Unified Schema: Pydantic-driven story graphs and node structures.
  • Stat-Based Branching: Transition between nodes based on complex condition evaluations.
  • Mutable State Engine: Snapshot and rollback support with isolated state variables.
  • Developer-First: Built-in CLI, JSON export, and performance benchmarking.
  • AI Extensions: Optional LLM-powered content generation via OpenRouter.

📜 Installation

# Basic installation
pip install story-builder

# With AI features
pip install "story-builder[ai]"

# With Visualization features
pip install "story-builder[viz]"

⚡ Quickstart (SDK Usage)

from story_builder import StoryGraph, Node, Choice, Effect, Engine

# 1. Define your story structure
story_graph = StoryGraph(
    start_node_id="intro",
    nodes={
        "intro": Node(
            id="intro",
            title="The Gatehouse",
            body="You stand before the ancient stone gate.",
            choices=[
                Choice(
                    trigger="Push the gate", 
                    target_node_id="inside",
                    effects=[Effect(target="strength", operation="increment", value=1)]
                )
            ]
        ),
        "inside": Node(
            id="inside",
            title="Castle Courtyard",
            body="Welcome to the inner sanctum.",
            choices=[]
        )
    }
)

# 2. Initialize the Engine
engine = Engine(story_graph)

# 3. Traverse the story
node, triggers, variables = engine.run("intro", variables={"strength": 10})
print(f"[{node.title}] {node.body}")

🕹️ CLI Usage

Play any story graph JSON directly from your terminal:

# Using the shortcut
story-builder play examples/minimal_story.json

# Or using python module
python -m story_builder.cli play examples/minimal_story.json

🎨 Visualize Your Story Graph

Generate a visual representation of your narrative graph.

1. Install extras

pip install "story-builder[viz]"

Note: This also requires GraphViz to be installed on your system if you want to render images.

2. Run the command

story-builder visualize examples/minimal_story.json

It will generate a .dot file and a .png file, and attempt to open the image.

Example Visualization: (Generated graph image will appear here)


Structure Your Story, Control Your World.

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

story_builder_sdk-0.1.0.tar.gz (18.3 kB view details)

Uploaded Source

Built Distribution

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

story_builder_sdk-0.1.0-py3-none-any.whl (16.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for story_builder_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fb07f3d4641a6f271f62eb33255e5918c7b6d00a5c675a899125c19d3afa218f
MD5 a257db5f6a278a79c3beb99a5ad4e0a5
BLAKE2b-256 2e4c4504948bae6e109c13c902cfc55f183bccada728d67c8755a66102089352

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for story_builder_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 469b1ff177d794f768a508d3482aeb4f63bdac689a0734faafdcc5496c9c535e
MD5 fd94e02103d45ec752b9877e115fc4a8
BLAKE2b-256 a9726955a3fe09bea872d8c418d3e5f1326fac9af653e9c89c1454f72c1c6edb

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