Skip to content

uv run with stdin #6467

@billy-doyle

Description

@billy-doyle

inspired by https://docs.astral.sh/uv/guides/scripts/#declaring-script-dependencies and some tweets being able to just send someone a command and boom they can run a py script

MRE:

billy@sa ~/uv_eof % uv run - <<EOF
print("hello world")
EOF
error: Failed to spawn: `-`
  Caused by: No such file or directory (os error 2)

Short dash(-) here represents stdin, similar to how k8s allows:

kubectl apply -f - <<EOF
apiVersion: v1
kind: ServiceAccount
metadata:
  name: kubectl-actions
  namespace: my-v2-restore
EOF

Some more details and how kubectl does it (in go tho ofc) https://stackoverflow.com/a/72168173/9992341 and https://github.com/kubernetes/cli-runtime/blob/v0.21.0/pkg/resource/builder.go#L245

basically turns any snippet someone else wants to run with

billy@sa ~/uv_eof % curl -LsSf https://astral.sh/uv/install.sh | sh && uv run - <<EOF               
print("hello world")
EOF

Metadata

Metadata

Assignees

Labels

enhancementNew feature or improvement to existing functionalityhelp wantedContribution especially encouraged

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions