The generator configuration needs to be added anywhere in .baml files to generate the baml_client in Python or Typescript.

We recommend running baml init to have this setup for you with sane defaults.

Here is how you can add a generator block:

generator MyGenerator{
  language "python"
  // This is where the generated baml-client will be written to
  project_root "../"
  test_command "poetry run python -m pytest"
  install_command "poetry add baml@latest"
  package_version_command "poetry show baml"
}
PropertyDescriptionOptionsDefault
languageThe language of the generated clientpython
project_rootThe directory where we’ll output the generated baml_client../
test_commandWhat baml test uses to run your playground tests
install_commandThe command for setting up the environment with all dependencies. baml update calls thisstring
package_version_commandThe command to get the version of the baml packagestring

Example generators

Python with poetry

generator MyGenerator{
  language "python"
  // This is where the generated baml-client will be written to
  project_root "../"
  test_command "poetry run python -m pytest"
  install_command "poetry add baml@latest"
  package_version_command "poetry show baml"
}

Python with venv

generator MyGenerator {
  language "python"
  project_root "../"
  test_command "source ./.venv/bin/activate && python -m pytest"
  install_command "source ./.venv/bin/activate && pip install -r requirements.txt"
  package_version_command "source ./.venv/bin/activate && pip show baml"
}

Using secret ops platforms

If you’re using software like Infisical or Doppler, do the following:

generator MyGenerator {
  language "python"
  project_root "../"
  // Add the prefix to the test command
  test_command "infisical run -- poetry run python -m pytest"
  install_command "poetry add baml@latest"
  package_version_command "poetry show baml"
}