mirror of
https://github.com/asciinema/asciinema.git
synced 2026-04-25 16:05:52 +03:00
[GH-ISSUE #300] [ integration ] expose python api #818
Labels
No labels
bug
compatibility
feature request
fit for beginners
help wanted
hosting
idea
improvement
packaging
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/asciinema#818
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @vsoch on GitHub (Apr 21, 2018).
Original GitHub issue: https://github.com/asciinema/asciinema/issues/300
This is probably a no brainer, but I'd like to be able to (programatically from within Python) have an easy way to control asciinema recording, so I can integrate it into my client's functions without needing to send commands to subprocess. I started to trace what was happening and come up with something (rather hacky):
but stopped because I was worried about not completely mimicking the parser that is defined here. If we could have discussion about how this might be done, I have a few ideas!
Expose Parser
you could expose functions to just return the parser for each command, that way a function like mine could do something like:
Python API?
As a developer, it would be really awesome to see documentation and examples for how to control from within Python. Given that we call a subshell, I think it should technically work to record from /bin/bash (or
$SHELL) and then do it's thing and exit right back where it left off :)Expose Generation Function
It would be more intuitive to expose a generation function that either prepares a dummy parser (akin to what I was trying to do) to pass on to RecordCommand, or a customization of RecordCommand so it takes more nicely named arguments, e.g.,
etc.! What I'm probably going to try is overriding the init function before I call it with something like this, and tweak until I have the minimum set of variables needed to get it working, haha.
And thank you so much for asciinema! It continues to be one of my favorite things, and I'm finally having some time to integrate it into some cool tools :)
@vsoch commented on GitHub (Apr 21, 2018):
Here is a quick example of something:
and then running (from within Python)
and then the file looks ok, even despite the stupid things I typed :)
Are there other users integrated asciinema like this? It seems like something that would definitely be wanted! I'm happy to use this hack I came up with, but wanted to bring up something more robust so others might benefit having it.
@ku1ik commented on GitHub (Apr 24, 2018):
Hey! Looks like you've figured the hard parts :)
If I understand correctly you would like to initiate recording session from your own Python code, right?
I think it would be quite straightforward to expose this functionality in even nicer API for such purposes.
I've been refactoring the code recently to make it more user-friendly, see here: https://github.com/asciinema/discussions/issues/38 - this one is for reading and writing asciicast files (not useful for you purpose though).
@vsoch commented on GitHub (Apr 25, 2018):
hey @sickill ! Yes this would be a really great feature to have. If you are interested, I got (most of it) working here, just for the commands that I needed (record and upload) for this library --> https://vsoch.github.io/helpme/helper-github specifically for record and submit. I'm really excited about using asciinema in this way - this client prompts the user for asking a question, records the terminal if they want to show an issue, and then submits to uservoice or Github. I can do other clients if anyone has ideas. Could you tell me more about the API you are developing for writing the files? What are example use cases of when we would want to do this?
@ku1ik commented on GitHub (Jan 12, 2019):
Hey I just released 2.0.2 with this high level API for recording: https://github.com/asciinema/asciinema/blob/develop/asciinema/init.py#L19
It's used by RecordCommand: https://github.com/asciinema/asciinema/blob/develop/asciinema/commands/record.py#L69-L78
Most of the arguments are optional, they have reasonable defaults, the only required one is path for the resulting asciicast file.