Skip to content

rawktron/inkpython

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Inkpython

Python runtime for ink (ported from inkjs) that loads compiled .ink.json files and plays them in pure Python.

Table of contents

Installation

From PyPI: pip install inkpython

Dependencies:

  • Runtime: none
  • Tests: pytest

Quickstart

from pathlib import Path
from inkpython import Story

story_json = Path("path/to/story.ink.json").read_text(encoding="utf-8-sig")
story = Story(story_json)

print(story.ContinueMaximally())

Working with a JSON file

Inkpython runs compiled ink JSON output (from inklecate or the official ink compiler).

If you load from disk, make sure to strip the BOM or read with utf-8-sig:

from pathlib import Path
from inkpython import Story

text = Path("story.ink.json").read_text(encoding="utf-8-sig")
story = Story(text)

CLI player

A simple CLI player is included:

inkpython path/to/story.ink.json

It prints output, lists choices, and lets you pick by number.

External functions

You can bind external functions via BindExternalFunction:

story.BindExternalFunction("message", lambda arg: print("MESSAGE:", arg))

If you need the text output from a function call, use EvaluateFunction(..., True):

result = story.EvaluateFunction("my_func", [1, 2], True)
# result == {"returned": <value>, "output": "text\n"}

Tests

pytest -q

License

MIT. See LICENSE.

About

A python port of inkle's ink scripting language runtime.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages