#python #environments #virtual #ad-hoc #offline #script #mode

app spyn

A tool for creating on-demand Python virtual environments

9 releases (5 breaking)

0.7.0 Jun 17, 2024
0.6.0 Mar 22, 2024
0.5.0 Mar 21, 2024
0.4.0 Mar 17, 2024
0.2.1 Mar 15, 2024

#397 in Network programming

Download history 312/week @ 2024-03-12 272/week @ 2024-03-19 2/week @ 2024-03-26 26/week @ 2024-04-02 98/week @ 2024-06-11 55/week @ 2024-06-18

153 downloads per month

MIT license

321 lines

What is Spyn?

Spyn is a tool for creating on-demand, ad-hoc virtual environments for running Python applications.

Spyn was heavily inspired by fades, but tries to improve upon the same concept:

  1. Spyn is written in Rust and comes as a binary executable, meaning you don't need to install it through script wrappers or taint your local Python installation. It will also not break when system Python versions get upgraded or reinstalled. Spyn also runs much quicker thanks to that fact
  2. Spyn uses uv for creating and managing virtual environments. This allows it to create virtuelenvs in fractions of seconds and be less prone to pip breakages and hiccups. It also supports running in offline mode, meaning it only uses its cache and avoids accessing the network thanks to uv.


spyn needs uv in order to operate correctly. Make sure you install it as described in the official docs.

The most convenient way is to use homebrew if you're on macOS, or run the following command:

$ curl -LsSf https://astral.sh/uv/install.sh | sh

You can use cargo install to install spyn:

$ cargo install spyn


You can use spyn to run a Python script, specifying the dependencies it needs:

$ spyn -d requests ./my_script.py

You can also mark dependencies in the script itself which are to be installed by spyn:

$ cat my_script.py
import os

import requests # spyn

print("Hello, World!")
$ spyn ./my_script.py

spyn even accepts lines marked with fades to provide backwards compatibility with fades!

If you want an interactive session with custom dependencies, spyn supports the --ipython flag, dropping you into an IPython shell with the dependencies you specify:

$ spyn --ipython -d requests
Using Python 3.11.2 interpreter at: /Users/rotemy/src/oss/spyn/.venv/bin/python3
Creating virtualenv at: /var/folders/bs/wqjbrbn948j78gb4303rjdcc0000gn/T/spyn.FDlEhIQvFyXR
Activate with: source /var/folders/bs/wqjbrbn948j78gb4303rjdcc0000gn/T/spyn.FDlEhIQvFyXR/bin/activate
Resolved 21 packages in 451ms
Installed 21 packages in 82ms

In [1]: import requests
In [2]: 


~619K SLoC