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 |
#625 in Network programming
709 downloads per month
17KB
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:
- 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
- Spyn uses
uv
for creating and managing virtual environments. This allows it to create virtuelenvs in fractions of seconds and be less prone topip
breakages and hiccups. It also supports running in offline mode, meaning it only uses its cache and avoids accessing the network thanks touv
.
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]:
Dependencies
~10–40MB
~619K SLoC