Scripting | pkgx/docs

Scripting

You can use pkgx as the shebangarrow-up-right for your scripts:

$ chmod +x ./my-script.py
$ ./my-script.py
3.9.17

Using env to invoke pkgx is typical for tools that have no POSIX location.

The -S parameter is required to pass multiple arguments.

Including Additional pkgs

Scripts are the glue that allows open source to be composed into powerful new tools. With our +pkg syntax you make anything in open source available to your script.

#!/usr/bin/env -S pkgx +openssl deno run

Deno.dlopen("libssl.dylib")

Robustness requires precisely specifying your environment:

#!/usr/bin/env -S pkgx bash>=4

source <(pkgx dev --shellcode)
# ^^ bash >=4 is required for this syntax, and eg macOS only comes with bash 3

Scripting for Various Languages & Their Dependencies

Use uv to import PyPi dependencies:

Use Bundlerarrow-up-right:

Use Denoarrow-up-right:

[!TIP] Probably you should specify a more precise Rust version as a plus-pkg arg.

Use Scriptistoarrow-up-right:

We think pkgx scripting is so powerful that we made a whole package manager to show it off.

https://github.com/pkgxdev/masharrow-up-right

We make use of pkgx scripting all over our repositories. Check them out!

Requiring a pkgx shebang is somewhat limiting. Instead you can use our cURL one-liner coupled with +pkg syntax to temporarily install pkgs and utilize them in your scripts:

Last updated