Python-first interactive fiction engine
Project description
Bardic
Bardic is a Python-first interactive fiction engine that lets you import your own classes and use real Python in your stories. It's built for modern Python web applications. It's also for people who want to make narrative games without learning web dev.
Write your branching narrative in a clean, simple syntax (inspired by Ink), and when you need complex logic, just use Python. Bardic is designed to be the "story layer" for games that need rich data models, complex state, and custom UIs. Bardic is frontend-agnostic and works with NiceGUI, Reflex, React+FastAPI, or any other frontend layer you want to build with. It compiles stories to JSON and is portable and versatile.
Why Bardic? A New Choice for Writers and Developers
You have great tools like Twine, Ink, and Ren'Py. So, why did I create Bardic?
Bardic is built for stories that get complex.
- Twine is fantastic for building "Choose Your Own Adventure" style branching stories.
- Ink is a brilliant, elegant language for managing branching state (like
GOTOs andGATHERs). - Bardic is for when your "state" isn't just a number or a string, but a complex Python object. It's for when you want to write:
- "I want this character to have an inventory, which is a list of
Itemobjects." - "I need to import my
Playerclass and callplayer.take_damage(10)." - "I want to simulate a full tarot deck, with 78
Cardobjects, each with its own properties and methods."
- "I want this character to have an inventory, which is a list of
Have you ever been writing and thought, "I wish I could just import my custom class and use it"? That's what Bardic does.
It bridges the gap between simple, text-based branching logic and the full power of a programming language, letting you use both in the same file.
A Quick Example
Bardic syntax is designed to be simple and stay out of your way. Here's a small story that shows off the core features:
# Import your own Python classes, just like in a .py file
from my_game.character import Player
:: Start
# Create a new Player object
~ hero = Player("Hero")
Welcome to your adventure, {hero.name}!
You have {hero.health} health.
+ [Look around] -> Forest
+ [Check your bag] -> Inventory
:: Forest
The forest is dark and spooky.
~ hero.sprint() # Call a method on your object
You feel a bit tired.
+ [Go back] -> Start
:: Inventory
# Use Python blocks for complex logic
@py:
if not hero.inventory:
bag_contents = "Your bag is empty."
else:
# Use list comprehensions, f-strings...
item_names = [item.name for item in hero.inventory]
bag_contents = f"You have: {', '.join(item_names)}"
@endpy
{bag_contents}
+ [Go back] -> Start
Core Features
- Write Python, Natively: Use
~for simple variable assignments or drop into full@py:blocks for complex logic. - Use Your Own Objects:
importyour custom Python classes (likePlayer,Card, orClient) and use them directly in your story. - Complex State, Solved: Bardic's engine can save and load your entire game state, including all your custom Python objects, right out of the box.
- You Write the Story, Not the UI: Bardic doesn't care if you use React, NiceGUI, or a terminal. It produces structured data for any UI.
- Use the NiceGUI template for a pure-Python, single-file game.
- Use the Web template (FastAPI + React) for a production-ready, highly custom web game.
- Clean, Writer-First Syntax: Focus on your story with a minimal, line-based syntax for passages (
::), choices (+), and text. - Visualize Your Story: Automatically generate a flowchart of your entire story to find highlighted dead ends or orphaned passages with the
bardic graphcommand. - Instant Start-Up: Get a working game in 60 seconds with
bardic init. It comes with a browser-based frontend pre-configured and ready to run with a single command. (NiceGUI, Reflex, or React -- take your pick.) - VS Code Integration: You can install the Bardic VS Code extension to get full syntax highlighting, code snippets and code folding in your IDE.
Quick Start (in 4 Steps)
Get a new game running in under 60 seconds.
1. Install Bardic:
pip install bardic
# Or with NiceGUI template support
pip install bardic[nicegui]
# Or with other optional dependencies, if you want them
pip install bardic[nicegui,reflex,web,dev]
2. Create a New Project: This creates a new folder with a full example game, ready to run in a pre-made frontend in your browser.
bardic init my-game
cd my-game
3. Install Dependencies:
The default template uses NiceGUI. If you didn't install with [nicegui], install the project dependencies:
pip install -r requirements.txt
4. Compile & Run!
# 1. Compile your story from .bard to .json
bardic compile example.bard -o compiled_stories/example.json
# 2. Run the game player
python player.py
Your game is now running at http://localhost:8080!
Installation Options
Bardic supports multiple UI frameworks. Choose the one you prefer:
| Framework | Install Command | Best For |
|---|---|---|
| NiceGUI | pip install bardic[nicegui] |
Pure Python, single-file games |
| FastAPI + React | pip install bardic[web] |
Production web apps |
| Reflex | pip install bardic[reflex] |
Python → React compilation |
Or install the core engine and add dependencies manually:
bardic init my-game
cd my-game
pip install -r requirements.txt
The Bardic Toolkit (CLI)
Bardic comes with a command-line interface to help you build your game.
bardic init my-game: Creates a new project from a template.bardic compile story.bard: Compiles your.bardfile into a.jsonfile that the engine can read.bardic play story.json: Plays your game directly in your terminal.bardic graph story.json: Generates a visual flowchart of your story (as a.pngor.svg).
Example Game: Arcanum
Need to see a large-scale project? The Arcanum cozy tarot reading game is built with Bardic. It's an example of using Bardic with custom Python classes, complex state, and a NiceGUI frontend.
Editor Support
VSCode Extension:
Get syntax highlighting and code snippets:
- Open VSCode
- Search "Bardic" in Extensions
- Install
Or install from command line:
code --install-extension katelouie.bardic
Where to Go Next?
- New to Bardic? I've put together a short tutorial course that walks you through all of the syntax and features of Bardic, from beginner to advanced.
- Want to see all the syntax? Check out the Language Specification for the full list of features, from loops to render directives.
- Want to build the engine? See our
CONTRIBUTING.mdfor details on the architecture and development setup. - Want VS Code integration? Download the Bardic VS Code extension with full syntax highlighting, snippets and code folding.
- See the DeepWiki detailed documentation generated from AI code indexing. It includes a lot of technical implementation details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bardic-0.2.0.tar.gz.
File metadata
- Download URL: bardic-0.2.0.tar.gz
- Upload date:
- Size: 141.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d603d20c8aad6bf55920abdacef0babdaa3821f47c54a30973fa2fd9222fda7
|
|
| MD5 |
7cfa65a9a17b2c082b3ec618354b3709
|
|
| BLAKE2b-256 |
95927a182b7e309415ee74de76d2c10ac05c77a908d9d8677eb6ac1a414aa29a
|
File details
Details for the file bardic-0.2.0-py3-none-any.whl.
File metadata
- Download URL: bardic-0.2.0-py3-none-any.whl
- Upload date:
- Size: 151.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5dd6f804c8e1a89ae792a2998f87755ff31fb7831a728f13005587068e5628cd
|
|
| MD5 |
f4c66c0244e82ad38bfd5bb5ccd712df
|
|
| BLAKE2b-256 |
dbce8a5e8af4e4c83f959a86cd01b74e2c1ac69969f986aa11db919c1b3bd855
|