Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Azure Functions supports three build options for publishing your Python apps to Azure. Choose your build method based on your local environment, app dependencies, and runtime requirements.
Quick comparison for build actions
| Deployment type | Where dependencies are installed | Typical use case |
|---|---|---|
| Remote build (recommended) | Azure (App Service) | Default, recommended for most users |
| Local build | Your machine | Linux/macOS devs, limited Windows scenarios |
| Custom dependencies | Handled via extra index URL or local install | Non-PyPI dependencies |
Deployment package considerations
When deploying your Python function app to Azure, keep these packaging requirements in mind:
- Package contents, not the folder: Deploy the contents of your project folder, not the folder itself.
- Root-level
host.json: Ensure a singlehost.jsonfile is at the root of the deployment package, not nested in a subfolder. - Exclude development files: You can exclude folders like
tests/,.github/, and.venv*/from the deployed package by including them in.funcignore. - The build environment must match the production environment: Your dependencies must be built on an ubuntu machine using the same python version as the production app. Remote build handles this scenario automatically.
- Dependencies must be installed into
./.python_packages/lib/site-packages: Remote build installs all dependencies listed inrequirements.txtinto the correct directory. - Keep deployment package size in mind: large dependency sets increase build time, cold start latency, and module import and initialization time. Applications with large scientific or ML libraries (including
pytorch) are especially impacted. - Remote build has a 60-second timeout: If dependency installation exceeds the limit, the build fails. In that case, consider using a local build and deploying with prebuilt dependencies.
- Module import has a 2-minute time limit: Python module loading and function indexing during startup has a 2-minute limit for Python 3.13 and above, or for older python versions with
PYTHON_ENABLE_INIT_INDEXINGenabled. If your app exceeds this, reduce top-level imports or use lazy imports (import modules inside the function body instead of at the global scope).
Remote build
Remote build is the recommended approach for a code-only deployment of your Python app to Functions.
With remote build, the Functions platform handles package installation and ensures compatibility with the remote runtime environment. Using remote build also results in a smaller deployment package.
You can use remote build when you publish your Python app using these tools:
- Azure Functions Core Tools: the
func azure functionapp publishcommand requests a remote build by default when publishing Python apps. - AZ CLI:
az functionapp deployment source config-zipuses remote build by default when deploying Python apps. - Visual Studio Code: the Azure Functions: Deploy to Azure... command always uses a remote build.
- Continuous delivery by using GitHub Actions: the Azure/functions-action@v1 action uses remote build when the
remote-buildparameter is set totruefor the Flex Consumption plan or whenscm-do-build-during-deploymentandenable-oryx-buildare set totruefor Dedicated plans.
To enable remote build for other scenarios, like Continuous delivery with Azure Pipelines, see Enabling Remote Build.
Remote build also supports custom package indexes when by using the PIP_EXTRA_INDEX_URL app setting. For more information, see Remote build.
Important
Remote build installs all dependencies listed in requirements.txt. To ensure all required packages are installed, be sure to include those dependencies in your requirements.txt file.
Local build
If you don't request a remote build, then dependencies are instead installed on your machine. The entire local project and dependencies are then packaged locally and deployed to your function app. Using local build results in a larger package upload.
You also need to install dependencies into the correct directory. Use pip install --target="./.python_packages/lib/site-packages" to install required dependencies into your local .python_packages/lib/site-packages folder.
For example, if you have your dependencies listed in a requirements.txt file, you can run this command:
pip install --target="./.python_packages/lib/site-packages" -r requirements.txt
Use local build when:
- You're developing locally on Linux or macOS.
- Remote build isn't available or is restricted.
- You want to define dependencies in a file other than
requirements.txt, such aspyproject.toml.
The following tools can be configured to use local build:
- Azure Functions Core Tools: use
func azure functionapp publishwith the--no-buildflag. - AZ CLI:
az functionapp deployment source config-zipwith the--build-remote=falseflag. - Continuous delivery by using GitHub Actions: set the
remote-buildparameter tofalsefor the Flex Consumption plan or setscm-do-build-during-deploymentandenable-oryx-buildtofalsefor Dedicated plans.
Important
When developing your Python apps on a Windows computer, don't use local build. Packages built on a Windows computer often have issues being deployed to and running on Linux in Azure Functions. Only use local build if you're confident the package runs on Linux based systems.
Custom dependencies
Azure Functions supports custom and other non-PyPI dependencies by using the PIP_EXTRA_INDEX_URL app setting or by creating a local build on a Linux or macOS computer.
Remote build with an extra index URL
When your private packages are available online, you can request a remote build after setting the private package location by using the PIP_EXTRA_INDEX_URL app setting.
When you set PIP_EXTRA_INDEX_URL, remote builds use this package feed during deployment. PIP_INDEX_URL replaces the package index,
so consider using PIP_EXTRA_INDEX_URL instead to prevent unexpected behavior.
Local packages or wheels
Local packages and wheels are supported when building python Azure Function apps.
To install these packages or wheels using remote build, you can include the dependencies in your requirements.txt file and deploy with remote build enabled.
For example, your requirements.txt file might look like the following snippet:
# Installing a custom wheel
<my_package_wheel>.whl
# Installing a local package
path/to/my/package
To install these dependencies using local build, install the dependencies into your local .python_packages/lib/site-packages folder and deploy with remote build disabled.
For example, if you have the packages defined in your requirements.txt file, you can install and publish using the following commands and Core Tools:
pip install --target="./.python_packages/lib/site-packages" -r requirements.txt
func azure functionapp publish <APP_NAME> --no-build