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.1.tar.gz (19.0 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.1-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: story_builder_sdk-0.1.1.tar.gz
  • Upload date:
  • Size: 19.0 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.1.tar.gz
Algorithm Hash digest
SHA256 c92c350ca3eacc1be65ef235a3ae77b185d5fd9b9f107aef5706b86c679ffdc0
MD5 370f8669e3921aaa89d6f3e755f67e84
BLAKE2b-256 779df8b43c248a9d69c4a14cf6bc1b4a0521eed66fcd828f98d6e456ed3b04e9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for story_builder_sdk-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f3185809b55a838e80520b6abf51398339e9a9a6db6ac03222a8d7b13fa0fca9
MD5 4499ba77ede7efa33d1befadf8319878
BLAKE2b-256 1097bf765e9a176819d430f540b12ebc0aecf9fe5e8f36f50a4b6a1757ae3edb

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