generator
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"
}
Property | Description | Options | Default |
---|---|---|---|
language | The language of the generated client | python | |
project_root | The directory where we’ll output the generated baml_client | ../ | |
test_command | What baml test uses to run your playground tests | ||
install_command | The command for setting up the environment with all dependencies. baml update calls this | string | |
package_version_command | The command to get the version of the baml package | string |
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"
}