Share via

Azure Functions python duckdb import error

Matthias 20 Reputation points
2026-04-22T11:20:19.4333333+00:00

I am trying to use the DuckDB Python library in Azure Functions deployed with Docker, but I am running into "ImportError: generic_type: type "ExplainType" is already registered!" at the line "import duckdb" when trying to run the function. This seems to be due to a conflict between the duckdb python bindings and some other library in the Azure Functions runtime.

It can be reproduced with:

  1. func init test --docker
  2. add "duckdb" to requirements.txt
  3. add "import duckdb" along with a test function to function_app.py
  4. deploy
  5. call the test function

This doesn't seem to happen when using the Oryx build based deployment.
Could it be caused by this ExplainType class being registered globally with pybind despite not being used?

Are there any fixes or workarounds for this issue? It is preventing me from deploying my application since Oryx build is not viable either in my case.

Azure Functions
Azure Functions

An Azure service that provides an event-driven serverless compute platform.

0 comments No comments

Answer accepted by question author

Siddhesh Desai 7,080 Reputation points Microsoft External Staff Moderator
2026-04-22T13:22:18.3966667+00:00

Hi @Matthias

Thank you for reaching out to Microsoft Q&A.

This issue occurs due to a native binary conflict between Duck DB’s Python bindings (implemented using pybind11) and the Azure Functions Python runtime when running in Docker. When duck dB is imported, its C++ bindings register global types such as Explain Type. In the Azure Functions Docker runtime, other native components (from the Functions host, worker process, or telemetry extensions) may already have initialized pybind-related type registries. As a result, when Duck DB attempts to register the same type again, Python raises the error: Import Error: generic type: type "Explain Type" is already registered! This is why the issue appears only in Docker-based Azure Functions, does not reproduce in a plain local Python environment, and often does not occur with Oryx builds—Oryx better isolates dependency compilation and native library loading. The failure happens at import time and is not caused by your function code logic.

Refer below points to resolve this issue or this is the workaround

Pin Duck DB to a stable version known to work better with Azure Functions

Some Duck DB versions changed pybind registration behavior, increasing the chance of conflicts. Avoid floating versions in requirements.txt.

Example:

duckdb==0.9.2

Avoid importing DuckDB at module load time (use lazy import) Import DuckDB inside the function handler instead of at the top level so that the Azure Functions worker finishes its native initialization first.

Example:

def main(req):
    import duckdb
    # rest of your logic

Use a custom slim base image instead of the default Azure Functions image

  • Build your own Docker image (for example, based on python:3.10-slim) and install azure-functions manually. This reduces preloaded native libraries and lowers the chance of pybind conflicts, though it requires more custom setup.
  • In your Dockerfile use the “Python-only” tag instead of the full App Service image. e.g. FROM mcr.microsoft.com/azure-functions/python:4-python3.11 (instead of 4-python3.11-appservice) This image doesn’t include the azureml-interpret library, so the conflict goes away.

Disable Application Insights native agent if enabled

In some cases, disabling native telemetry reduces native extension load conflicts:

APPLICATIONINSIGHTS_ENABLE_AGENT

This is a mitigation and may not work in all environments.

Move DuckDB processing out of Azure Functions if possible

If DuckDB is a hard requirement, consider running it in Azure Container Apps or Azure App Service, and use Azure Functions only as a trigger or orchestrator. This avoids the Functions runtime native limitations.

Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.