Skip to main content

Load and play ASCII Motion animations in your terminal

Project description

PyAsciiMotion

Play ASCII Motion animations in your Python terminal.

Parses session files (.json, .asciimtn), JSON exports, and plain-text frame files from ascii-motion.app — then renders them with full ANSI color support, frame-by-frame playback, and interactive controls.

Install

pip install pyasciimotion

Quick start

from pyasciimotion import AsciiMotion

anim = AsciiMotion.load("demo.json")
anim.play()

Python API

Loading

from pyasciimotion import AsciiMotion

# From a file
anim = AsciiMotion.load("path/to/file.json")
anim = AsciiMotion.load("path/to/file.asciimtn")
anim = AsciiMotion.load("path/to/file.txt")

# From a string
anim = AsciiMotion.from_string(json_text, name="my animation")

Inspecting

print(anim.frame_count)      # number of frames
print(anim.width, anim.height)
print(anim.meta.frame_rate)
print(anim.meta.name)

# Iterate frames
for frame in anim:
    print(frame.to_plain_text())

# Access a single frame
frame = anim[3]
text = anim.frame_text(3)

Playing

# Interactive playback (blocking, keyboard controls)
anim.play(fps=10, loop=True, color=True)

# Render a single frame to stdout
anim.render(index=0, color=True)

Keyboard controls during playback

Key Action
Space Pause / Resume
q Quit
. or ] Step forward
, or [ Step backward
0 Jump to first frame
+ Increase FPS
- Decrease FPS

Advanced player

player = anim.player(fps=12, loop=True, color=True)
player.play(blocking=False)   # runs in background thread

player.pause()
player.resume()
player.seek(10)
player.step(1)
player.fps = 24
player.stop()

print(player.state)           # State.PLAYING, State.PAUSED, etc.
print(player.current_frame)

Low-level access

from pyasciimotion import load, render_frame, Cell, Frame

animation = load("demo.json")
frame = animation.get_frame(0)

cell = frame.cell_at(5, 3)
print(cell.char, cell.fg, cell.bg)

for cell in frame.row(0):
    print(cell.char, end="")

CLI

pyasciimotion play demo.json
pyasciimotion play demo.json --fps 24 --no-loop --no-color
pyasciimotion info demo.json
pyasciimotion frame demo.json --index 3
pyasciimotion frame demo.json --index 0 --plain

Also works via module:

python -m pyasciimotion play demo.json

Supported formats

Format Extension Description
Session v1/v2 .json, .asciimtn Full project state from ascii-motion.app
JSON export .json Compact frame data with color dictionaries
Plain text .txt Character-only frames separated by ---

Architecture

pyasciimotion/
├── __init__.py    # Public API (AsciiMotion class)
├── models.py      # Cell, Frame, Animation, AnimationMeta
├── parser.py      # File format detection and parsing
├── renderer.py    # ANSI terminal rendering
├── player.py      # Threaded playback with controls
├── cli.py         # Command-line interface
└── utils.py       # Terminal detection, formatting

The parser auto-detects format from file extension and content structure. The renderer uses 24-bit ANSI color sequences (truecolor). The player runs playback on a background thread with pause/resume/seek via threading primitives.

Requirements

  • Python 3.10+
  • No external dependencies

License

MIT

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

pyasciimotion-0.1.0.tar.gz (851.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyasciimotion-0.1.0-py3-none-any.whl (13.9 kB view details)

Uploaded Python 3

File details

Details for the file pyasciimotion-0.1.0.tar.gz.

File metadata

  • Download URL: pyasciimotion-0.1.0.tar.gz
  • Upload date:
  • Size: 851.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for pyasciimotion-0.1.0.tar.gz
Algorithm Hash digest
SHA256 86cab53a7454bf5f567e61d4ca9dc7e6e059c909be49bed07fcc410bd632bfa5
MD5 c307cb6a5b85d7addc4380bc4276cb0f
BLAKE2b-256 bc082449cd091e4132521af2498fbcd4fa3eb8326b6cd468e3853afaea494fed

See more details on using hashes here.

File details

Details for the file pyasciimotion-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pyasciimotion-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for pyasciimotion-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fb38ad3549b9a1dd985b6f46575e72e1a52ddbd4d22f57ec6039e4773f231a5b
MD5 3ec089759ac83ce2cef4c39c57318266
BLAKE2b-256 a4a0f21e3918ae77145db7e46e169052de31c259c9efeadb132cdc6f0e2d7eb2

See more details on using hashes here.

Supported by

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