spyn

Crates.iospyn
lib.rsspyn
version0.7.0
sourcesrc
created_at2024-03-15 11:47:41.912762
updated_at2024-06-17 13:02:05.398374
descriptionA tool for creating on-demand Python virtual environments
homepagehttps://github.com/vmalloc/spyn
repositoryhttps://github.com/vmalloc/spyn
max_upload_size
id1174661
size51,480
Rotem Yaari (vmalloc)

documentation

README

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.

Installation

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

Usage

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]: 
Commit count: 41

cargo fmt