uvtrick
A fun party trick, via
uvand pickle, to run Python code from another venv ... into this one.
Quickstart
You can install this tool via:
uv pip install uvtrick
Usage
External scripts
There are a few ways to use this library. The first one is to use the load function to point
to a Python script that contains the function you want to use. This function assumes that the
script carries inline script metadata.
from uvtrick import load
# Load the function `add` from the file `some_script.py`
# It runs in another virtualenv, but you get back the response via pickle.
# Be aware of the limitations, please only consider base Python objects.
add = load("some_script.py", "add")
# This result is from the `some_script.py` file, running in another virtualenv
# with `uv`. A pickle in a temporary file is used to communicate the result.
add(1, 2) # 3
From within Python
But you can also take it a step further and use the Env class to run a function in a specific environment.
from uvtrick import Env
# For illustration purposes, let's assume that rich is not part of the current environment.
# Also note that all the imports happen inside of this function.
def uses_rich():
from rich import print
from importlib import metadata
version = metadata.version("rich")
print(f"hello from rich=={version}")
# This runs the function `uses_rich` in a new environment with the `rich` package installed.
# Just like the `load` function before, the result is returned via pickle.
Env("rich", python="3.12").run(uses_rich)
This approach is pretty useful if you are interested in running the same function in different versions of a dependency to spot a performance regression. You might be able to do that via something like:
from uvtrick import Env
def uses_rich(a, b):
from rich import print
from importlib import metadata
version = metadata.version("rich")
print(f"hello from rich=={version}")
return a + b
for version in (10, 11, 12, 13):
Env(f"rich=={version}", python="3.12").run(uses_rich, a=1, b=2)
Be aware that a lot of pickling is happening under the hood here. This can be a problem if you are trying to pickle large objects
or if your function is returning an object that needs a dependency that is not installed in the environment that is calling Env.
Also note that thusfar this entire project is merely the result of a very entertaining recreational programming session. We might want to gather some community feedback before suggesting production usage.
Metadata
Release files for uvtrick 0.4.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| uvtrick-0.4.2.tar.gz | 17.7 kB | Without provenance | Details for uvtrick-0.4.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| uvtrick-0.4.2-py3-none-any.whl | Python 3 | none | any | Details for uvtrick-0.4.2-py3-none-any.whl |
Total release size: 22.8 kB
Release files / uvtrick-0.4.2.tar.gz
| Download URL | uvtrick-0.4.2.tar.gz |
|---|---|
| Size | 17.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e76e109a9af951491cb202e50d244274510c208605109dfca9552a890a8455e3
|
|
BLAKE2b-256 checksum How to use checksums |
f65ea51b560228b2abacdae3f17b8b39adbee6e74c27d1f5bdb8500b1558a3ad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.13
|
Release files / uvtrick-0.4.2-py3-none-any.whl
| Download URL | uvtrick-0.4.2-py3-none-any.whl |
|---|---|
| Size | 5.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c32ad6fbbf358055fb150aa1ec94aa73d66f6b4df11c28bbd9572cc8e4c0eb78
|
|
BLAKE2b-256 checksum How to use checksums |
4ce7c33ac3f7adc35fb6775877d4207ac84f4df821cb18c05b9890086f31981b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.13
|
Security for uvtrick 0.4.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.