Skip to content

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

frompathlibimportPathfrominkpythonimportStorystory_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:

frompathlibimportPathfrominkpythonimportStorytext=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", 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"}

Tests

pytest -q

License

MIT. See LICENSE.

About

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

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages