Skip to main content

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.

Metadata

Release files for inkpython 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for inkpython 0.1.0
File Size Uploaded
inkpython-0.1.0.tar.gz 53.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for inkpython 0.1.0
File Interpreter ABI Platform
inkpython-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 118.4 kB

Release files / inkpython-0.1.0.tar.gz

Download URL inkpython-0.1.0.tar.gz
Size 53.6 kB
Tags Source
SHA-256 checksum
How to use checksums
ad7ac4391a68eb29da6245a9edcacca9a5aa95ffa46691201833a1337f41cae6
BLAKE2b-256 checksum
How to use checksums
e5d00644f17f4652e98e9f99630e4987f7aeac29267ede71ddb4edd556745d12
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.14

Release files / inkpython-0.1.0-py3-none-any.whl

Download URL inkpython-0.1.0-py3-none-any.whl
Size 64.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
92bbeef7ffe55f5c9dc3c8c696c62887d6d73918cdaa2590a81de64c2a06dd0f
BLAKE2b-256 checksum
How to use checksums
430106c691594eb810edd9fcdd0e2f4f674e95d8c173b82544aab0b4fcd4c57f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.14

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page