La vida es muy corta para espera por pip install

@hiancd

Pip Replacement

Python Manager

import requests
from rich.pretty import pprint

resp = requests.get("https://peps.python.org/api/peps.json")
data = resp.json()
pprint([(k, v["title"]) for k, v in data.items()][:10])

Script execution

# /// script
# dependencies = [
#   "requests<3",
#   "rich",
# ]
# ///

import requests
from rich.pretty import pprint

resp = requests.get("https://peps.python.org/api/peps.json")
data = resp.json()
pprint([(k, v["title"]) for k, v in data.items()][:10])

PEP 723 – Inline script metadata

# Add dependencies to a script
uv add --script example.py 'requests<3' 'rich'
from uvtrick import Env
from sklearn.datasets import make_regression
X, y = make_regression(n_samples=10_000, n_features=10, random_state=42)
def bench(X,y):
	from time import time
	from sklearn.decomposition import PCA
	tic = time()
	pca = PCA(n_components=2).fit(X,y)
	toc=time()
	return toc-tic

print("Running sckit-learn benchmarks")
for version in ("1.4", "1.5"):
	for i in range(4):
		timed = Env(f"scikit-learn=={version}").run(bench, X, y)
		print(version, timed)
# https://youtu.be/jXWIxk2brfk?t=295&si=MIBYD6N14sgAB2x0

Tricks Libraries

def bench(X,y):
	from time import time
	from sklearn.decomposition import PCA
	tic = time()
	pca = PCA(n_components=2).fit(X,y)
	toc=time()
	return toc-tic

  
print("Running sckit-learn benchmarks")
for version in ("1.4", "1.5"):
	for i in range(4):
		timed = Env(f"scikit-learn=={version}").run(bench, X, y)
		print(version, timed)
        
# Source
# https://youtu.be/jXWIxk2brfk?t=295&si=MIBYD6N14sgAB2x0

Run Packages

Project Manager

# application
uv init --app example-app

# library
uv init --lib example-app

Package Manager

$ uv --help
An extremely fast Python package manager.

Usage: uv [OPTIONS] <COMMAND>

Commands:
  run      Run a command or script
  init     Create a new project
  add      Add dependencies to the project
  remove   Remove dependencies from the project
  sync     Update the project's environment
  lock     Update the project's lockfile
  export   Export the project's lockfile to an alternate format
  tree     Display the project's dependency tree
  tool     Run and install commands provided by Python packages
  python   Manage Python versions and installations
  pip      Manage Python packages with a pip-compatible interface
  venv     Create a virtual environment
  build    Build Python packages into source distributions and wheels
  publish  Upload distributions to an index
  cache    Manage uv's cache
  self     Manage the uv executable
  version  Display uv's version
  help     Display documentation for a command

La vida es muy corta para espera por pip install

@hiancd

La vida es muy corta para esperar por un pip install

By Hian Cañizares

La vida es muy corta para esperar por un pip install

  • 109