Skip to main content

High-level command-line abstraction

Project description

Scriptor

Run command-line programs in Python


Pypi version build codecov Documentation Status PyPI pyversions

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

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

scriptor-0.2.0.tar.gz (113.2 kB view details)

Uploaded Source

Built Distribution

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

scriptor-0.2.0-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file scriptor-0.2.0.tar.gz.

File metadata

  • Download URL: scriptor-0.2.0.tar.gz
  • Upload date:
  • Size: 113.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.10

File hashes

Hashes for scriptor-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4fe7d1b423554de72ba685c71b891f0e58a3816d57cc2209b46d467968736caa
MD5 7be48c180faf3825dfe07b463e01eb4b
BLAKE2b-256 9715788ffd9bb8b1a3b8af1a3aba5454a4b857c997d177b7a0ee670e4ebecfb8

See more details on using hashes here.

File details

Details for the file scriptor-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: scriptor-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 15.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.10

File hashes

Hashes for scriptor-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cad4275cec494076c90c0cc1895cf09d39953f7931884d83893132431a2fa204
MD5 d1911ab979001935179c8ddc604fd40c
BLAKE2b-256 d3244937074e8dc3a2ed408404e95cb887641eeae59be7c7eb7c1ef7f0b4305c

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