Python runtime for ink (ported from inkjs) that loads compiled .ink.json files and plays them in pure Python.
From PyPI: pip install inkpython
Dependencies:
- Runtime: none
- Tests:
pytest
frompathlibimportPathfrominkpythonimportStorystory_json=Path("path/to/story.ink.json").read_text(encoding="utf-8-sig")
story=Story(story_json)
print(story.ContinueMaximally())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:
frompathlibimportPathfrominkpythonimportStorytext=Path("story.ink.json").read_text(encoding="utf-8-sig")
story=Story(text)A simple CLI player is included:
inkpython path/to/story.ink.jsonIt prints output, lists choices, and lets you pick by number.
You can bind external functions via BindExternalFunction:
story.BindExternalFunction("message", lambdaarg: 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"}pytest -qMIT. See LICENSE.