Show HN: Pysolate – Isolate your script, without installing anything

Show HN: Pysolate – Isolate your script, without installing anything

Simply journey your standalone script in an remoted digital environment.


  • Runs your script in its acknowledge digital environment
  • Mechanically downloads dependencies
  • Permits to specify a required Python model
  • No exterior instruments (e.g. pipx) required to journey your script. Best Python.
  • Discovers Python variations put in by pyenv


  • Runs on each Python 2.7 and Python 3.
  • When working on older methods (Python < 3.3), it wants virtualenv to be
    put in.


  1. Distribute a script, with out assuming your customers have an exterior instrument
    put in, akin to pipx.
  2. Distribute a script, with out requiring your customers to setup a
    digital setting and manually set up its dependencies.
  3. Simply bundle a Python script in a non-Python undertaking
  4. Add a supporting script (e.g. construct the undertaking or run assessments) avoiding
    potential conflicts along with your undertaking’s dependencies.

How does it work

Each time a pysolate script runs it would

  • detect if the personal digital env has already been created
  • in any other case:
    • attempt to discover a model of Python appropriate with the script
    • create the personal digital setting
    • set up dependencies
  • swap to the right digital setting
  • run the script


With a purpose to use pysolate in your script, it is advisable be certain it masses earlier than
your script executes. Right here is an instance script that reveals how that may be

# SPDX-License-Identifier: Apache-2.0
# Instance pysolate script:
# 1) Import required libs
import os, hashlib, pathlib, urllib.request

# 2) Load pysolate
_f = / ".pysolate"
_u = ""
_, _c = _f.exists() or urllib.request.urlretrieve(_u, _f), open(_f).learn()

# 3) Guarantee we aren't getting hacked
_h = "a62bb50cd98da1995897a9f97a5b8549a1e0090e67fff970f8025db7b1b45c82"
assert hashlib.sha256(_c.encode("utf-8")).hexdigest() == _h, "SHA256 Mismatch"

# 4) Configure and execute pysolate
    compile(_c, "load_pysolate", "exec"),
    {"dependencies": ["click >=7.0"], "python": "3.7"},

# 5) Run your script
import sys
import click on

click on.echo("Hey from Python %d.%d o/" % sys.version_info[:2])

By working this script for the primary time you get hold of:

$ python
04: 45: 40  INFO |     Creating venv | ~/.native/share/pysolate/
04: 45: 42  INFO |   Putting in deps
Hey from Python 3.7 o/

Subsequent runs don’t recreate the env, or set up the dependencies:

$ python
Hey from Python 3.7 o/

Or you may run in debug mode, to see all the pieces that occurs

$ PYS_LOG=DEBUG python2
04: 47: 04 DEBUG |    No lively venv | ~/.native/share/pyenv/variations/3.7.5rc1/bin/python
04: 47: 04 DEBUG |   Good Python ver | 3.7.5rc1
04: 47: 04  INFO |     Creating venv | ~/.native/share/pysolate/
04: 47: 07  INFO |   Putting in deps
Accumulating click on>=7.0
  The utilization of cached on on-7.1.2-py2.py3-none-any.whl
Inserting in silent functions: click on on
Effectively put in click on on-7.1.2
04: 47: 07 DEBUG |        Restarting | ~/.native/half/pysolate/
04: 47: 07 DEBUG |  Ravishing vigorous venv | ~/.native/half/pysolate/
04: 47: 07 DEBUG |   Beginning script | ~/src/pysolate/
Howdy from Python 3.7 o/

Show that on this case we’re using some elements (pathlib and
urllib.question) which are not readily available on Python 2.7. In case you take pleasure in to protect
compatibility with legacy variations, procure a see at inside the repo.


Configuration options can even be specified by passing a dictionary object to
exec, take pleasure in proven inside the occasion above.
Most of them may maybe even be configured with environment variables, by using the
prefix PYS_. As an illustration $PYS_LOG or $PYS_HOME.


(required, can not be area by env)

The dependencies your script needs in utter to journey, as an inventory of strings.
In case your script has no dependencies, you like to circulation the price (), as pysolate
makes use of this variable to detect if is being executed.


(non-mandatory, default: INFO)

The logging stage you need pysolate to journey with.


(non-mandatory, default: ~/.native/half/pysolate)

The positioning the preserve pysolate will retailer the entire inside most repositories by default.
This itemizing shall be created if it does not exist.



The positioning of the inside most digital environment for mainly probably the most up to date script.
By default the environment shall be situated inside PYS_HOME and its title based
upon the title of the script plus its sha1 hash.
Environment this feature potential that you may retailer the inside most digital environment
exterior PYS_HOME.


(non-mandatory, default: None, can not be area by env)

Specifies the desired Python model. May even be both a string or a callable.
If a callback is specified, this could obtain a tuple (take pleasure in sys.version_info)
and may maybe unbiased return Ravishing for a effectively marvelous model.


Please enter your comment!
Please enter your name here