Skip to main content

Static Interactive Fiction Generator

Project description

Grimoire

Grimoire is a Python library to create interactive fiction. What makes Grimoire unique is that it pre-renders all possible choices and simply outputs linked HTML files.

Installation

pip install grimoire-if

Usage

Check out some examples.

Your story begins

Begin by instantiating a Grimoire app.

from grimoire import Grimoire


app = Grimoire()

Then create our stories initial page.

@app.page
def start(state):
    state['name'] = 'Grimoire'
    return f"Hello, {state['name']}!", state

You can render our (rather boring) story right now by calling the app's render method.

app.render()

Grimoire added all the html files (in this case only the index.html file) into the site/ directory.

You can optionally pass a state class when creating your app.

@datalass
class State:
    name: Optional[str] = None


app = Grimoire(state=State)

@app.start
def start(state):
    state.name = 'Grimoire'
    return f"Hello, {state.name}!", state

Grimoire uses hype to render html and you can use it in your render functions.

from hype import *


@app.start
def start(state):
    state.name = 'Grimoire'
    return H1(f"Hello, {state.name}!"), state

Choose your own destiny

Let's add some options.

@app.option(start, "Next")
def next(state):
    return P("We're really moving now!"), state

Try rendering again. If you reload the index.html file, you should now see a link (Next) that brings you to the next page.

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

grimoire-if-0.0.5.tar.gz (3.6 kB view hashes)

Uploaded Source

Built Distribution

grimoire_if-0.0.5-py3-none-any.whl (4.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page