> ## Documentation Index
> Fetch the complete documentation index at: https://anaconda.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# bake_image

```python expandable theme={null}
bake_image(
    pypi: Optional[Dict[str, str]] = None,
    conda: Optional[Dict[str, str]] = None,
    requirements_file: Optional[str] = None,
    pyproject_toml: Optional[str] = None,
    base_image: Optional[str] = None,
    python: Optional[str] = None,
    logger: Optional[Callable[[str], Any]] = None,
    cache_name: Optional[str] = None
)
```

Bake a Docker image with the specified dependencies.

This is a composable building block that can be used standalone or
combined with AppDeployer to deploy apps with custom images.

**Parameters:**

<ParamField path="pypi" type="object">
  Dictionary of PyPI packages to install. Keys are package names, values are version specifiers. For example, `{"flask": ">=2.0", "requests": ""}`. Mutually exclusive with `requirements_file` and `pyproject_toml`.
</ParamField>

<ParamField path="conda" type="object">
  Dictionary of conda packages to install.
</ParamField>

<ParamField path="requirements_file" type="string">
  Path to a `requirements.txt` file. Mutually exclusive with `pypi` and `pyproject_toml`.
</ParamField>

<ParamField path="pyproject_toml" type="string">
  Path to a `pyproject.toml` file. Mutually exclusive with `pypi` and `requirements_file`.
</ParamField>

<ParamField path="base_image" type="string">
  Base Docker image to build from. Defaults to the platform default image.
</ParamField>

<ParamField path="python" type="string">
  Python version to use, such as `3.11.0`. If not set, uses the Python already present in `base_image` and installs dependencies into it. If set, a new Python environment at that version is created inside the base image, and all dependencies are installed into it.
</ParamField>

<ParamField path="logger" type="function">
  Logger function for progress messages.
</ParamField>

**Returns:**

<ResponseField name="value" type="BakedImage">
  A named tuple containing `image` (the baked Docker image URL) and `python_path` (the path to the Python executable in the image).
</ResponseField>

**Raises:**

* **ImageBakingException**: If baking fails or if invalid parameters are provided.

**Examples:**

Bake with PyPI packages:

```python theme={null}
result = bake_image(pypi={"flask": ">=2.0", "requests": ""})
print(result.image)
```

Bake from requirements.txt:

```python theme={null}
result = bake_image(requirements_file="./requirements.txt")
```

Bake from pyproject.toml:

```python theme={null}
result = bake_image(pyproject_toml="./pyproject.toml")
```

Combine with AppDeployer:

```python theme={null}
from metaflow.apps import bake_image, AppDeployer

baked = bake_image(pypi={"flask": ">=2.0"})
deployer = AppDeployer(name="my-app", port=8080, image=baked.image)
deployed = deployer.deploy()
```
