Scriptor
Run command-line programs in Python
What is it?
Scriptor is a high-level library for command-line. Scriptor makes it easy to integrate other CLI programs to your Python application.
Core features:
- Run programs sync or async using the same syntax
- High-level program abstraction
- Easy program parametrization
Install it from PyPI:
pip install scriptor
Why Scriptor?
Scriptor abstracts subprocess and asyncio.subprocess
to the same syntax making it easy to use both of them and
switch between.
>>> from scriptor import Program
>>> python = Program("python3")
>>> # Call the program (and wait for finish)
>>> python("myscript.py")
More Examples
Here are some examples:
>>> # Parametrize a script
>>> python("myscript.py", report_date="2022-11-11")
>>> # Use different current working directory
>>> python.use(cwd="path/to/dir")("myscript.py")
>>> # Run script with output (in stdout)
>>> python("print_hello.py")
'Hello world'
>>> # Run failing script
>>> python("failing.py")
Traceback (most recent call last):
...
scriptor.process.ProcessError: Traceback (most recent call last):
File "failing.py", line 1, in <module>
raise RuntimeError("Oops!")
RuntimeError: Oops!
Start a process:
>>> process = python.start("print_hello.py")
>>> process.finished
False
>>> # Wait for the process to finish
>>> process.wait()
>>> # Raise error if process failed
>>> process.raise_for_return()
>>> # Read the results
>>> process.read()
'Hello world'
Some more examples with async:
>>> # Parametrize a script
>>> await python.call_async("myscript.py", report_date="2022-11-11")
>>> # Run script with output (in stdout)
>>> await python.call_async("print_hello.py")
'Hello world'
Start with async:
>>> process = await python.start_async("print_hello.py")
>>> process.finished
False
>>> # Wait for the process to finish
>>> process.wait()
>>> # Raise error if process failed
>>> process.raise_for_return()
>>> # Read the results
>>> process.read()
'Hello world'
Change settings ie. the current working directory:
>>> git = Program('git')
>>> repo_1 = git.use(cwd="path/to/repo_1")
>>> repo_2 = git.use(cwd="path/to/repo_2")
>>> repo_1("status")
"""On branch main
nothing to commit, working tree clean"""
See more from the documentation.
If the library helped you, consider buying a coffee for the maintainer ☕.
Author
- Mikael Koli - Miksus - koli.mikael@gmail.com
Metadata
Release files for scriptor 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| scriptor-0.2.0.tar.gz | 113.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| scriptor-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 128.5 kB
Release files / scriptor-0.2.0.tar.gz
| Download URL | scriptor-0.2.0.tar.gz |
|---|---|
| Size | 113.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4fe7d1b423554de72ba685c71b891f0e58a3816d57cc2209b46d467968736caa
|
|
BLAKE2b-256 checksum How to use checksums |
9715788ffd9bb8b1a3b8af1a3aba5454a4b857c997d177b7a0ee670e4ebecfb8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.8.10
|
Release files / scriptor-0.2.0-py3-none-any.whl
| Download URL | scriptor-0.2.0-py3-none-any.whl |
|---|---|
| Size | 15.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cad4275cec494076c90c0cc1895cf09d39953f7931884d83893132431a2fa204
|
|
BLAKE2b-256 checksum How to use checksums |
d3244937074e8dc3a2ed408404e95cb887641eeae59be7c7eb7c1ef7f0b4305c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.8.10
|