Command-Line Interface

Hy provides a handful of command-line programs for working with Hy code.

hy

hy is a command-line interface for Hy that in general imitates the program python provided by CPython. For example, hy without arguments launches the REPL if standard input is a TTY and runs the standard input as a script otherwise, whereas hy foo.hy a b runs the Hy program foo.hy with a and b as command-line arguments. See hy --help for a complete list of options and Python’s documentation for many details. Here are some Hy-specific details:

-m <module>

Much like Python’s -m, but the input module name will be mangled.

--spy

Print equivalent Python code before executing each piece of Hy code in the REPL:

=> (+ 1 2)
1 + 2
------------------------------
3
--repl-output-fn

Set the REPL output function. This can be the name of a Python builtin, most likely repr, or a dotted name like foo.bar.baz. In the latter case, Hy will attempt to import the named object with code like (import foo.bar [baz]).

hy2py

hy2py is a program to convert Hy source code into Python source code. Use hy2py --help for usage instructions. It can take its input from standard input, or from a file or module name provided as a command-line argument. In the case of a module name, the current working directory should be the parent directory of that module, and the output parameter (--output/-o) is required. When the output parameter is provided, the output will be written into the given folder or file. Otherwise, the result is written to standard output.

Warning

hy2py can execute arbitrary code (via macros, eval-when-compile, etc.). Don’t give it untrusted input.

hyc

hyc is a program to compile files of Hy code into Python bytecode. Use hyc --help for usage instructions. The generated bytecode files are named and placed according to the usual scheme of your Python executable, as indicated by importlib.util.cache_from_source().

Warning

hyc can execute arbitrary code (via macros, eval-when-compile, etc.). Don’t give it untrusted input.