{"id":6629,"library":"firebase-functions","title":"Firebase Functions Python SDK","description":"The `firebase-functions` Python SDK enables developers to create and deploy serverless functions that respond to events in their Firebase projects and Google Cloud environment. It leverages Cloud Functions for Firebase (2nd gen) and integrates with various Firebase features like Firestore, Realtime Database, Authentication, and HTTPS requests. The library is actively maintained with frequent releases, with the current version being 0.5.0.","status":"active","version":"0.5.0","language":"en","source_language":"en","source_url":"https://github.com/firebase/firebase-functions-python","tags":["firebase","cloud functions","serverless","gcp","python"],"install":[{"cmd":"pip install firebase-functions","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Required for interacting with most Firebase services (e.g., Firestore, Authentication) within Cloud Functions and for app initialization.","package":"firebase-admin","optional":false}],"imports":[{"symbol":"https_fn","correct":"from firebase_functions import https_fn"},{"symbol":"firestore_fn","correct":"from firebase_functions import firestore_fn"},{"symbol":"options","correct":"from firebase_functions import options"},{"note":"You must explicitly import `firebase_admin` before calling `initialize_app()` or you will encounter a `NameError`. Ensure `firebase_admin` is also in your `requirements.txt`.","wrong":"import firebase_admin; initialize_app()","symbol":"initialize_app","correct":"from firebase_admin import initialize_app"}],"quickstart":{"code":"import os\nfrom firebase_functions import https_fn\nfrom firebase_admin import initialize_app\n\n# Initialize the Firebase Admin SDK. When deployed to Cloud Functions,\n# the SDK automatically detects the environment's service account credentials.\ninitialize_app()\n\n@https_fn.on_request()\ndef hello_world(request: https_fn.Request) -> https_fn.Response:\n    \"\"\"Responds to an HTTP request with a 'Hello from Python!' message.\"\"\"\n    # Example of accessing environment variables (if any are set during deployment)\n    message_prefix = os.environ.get('MESSAGE_PREFIX', 'Hello')\n\n    # Check for a 'name' query parameter or use a default.\n    name = request.args.get('name', 'World')\n\n    return https_fn.Response(f\"{message_prefix}, {name} from Python!\")","lang":"python","description":"This quickstart defines a simple HTTP-triggered function that responds with a greeting. It demonstrates initializing the Firebase Admin SDK (which is automatic in Cloud Functions environments) and handling basic request parameters. To deploy, save this as `main.py` in your functions directory, add `firebase-functions` and `firebase-admin` to `requirements.txt`, and run `firebase deploy --only functions`."},"warnings":[{"fix":"Be aware of potential changes and review release notes carefully. Consider stability requirements for production applications.","message":"Python support for Cloud Functions for Firebase is in Public Preview. This means the functionality might change in backward-incompatible ways, is not subject to any SLA or deprecation policy, and may receive limited support.","severity":"gotcha","affected_versions":"All versions (as of 0.5.0)"},{"fix":"Update your Python environment to Python 3.10 or newer. When deploying, ensure `runtime` is explicitly set to `python310`, `python311`, `python312`, or `python313` if not using the default (which is currently 3.13).","message":"The `firebase-functions` library requires Python 3.10 or higher. The `firebase-admin` SDK (a common dependency) also dropped support for Python 3.7 and 3.8, and deprecated 3.9, with version 7.0.0. Ensure your local environment and deployment runtime are on a supported Python version (3.10-3.13).","severity":"breaking","affected_versions":"firebase-functions >= 0.1.0, firebase-admin >= 7.0.0"},{"fix":"Always include `import firebase_admin` at the top of your function file, even if you only use submodules. Ensure `firebase-admin` is in `requirements.txt`.","message":"When using `firebase-admin` within your functions, you must explicitly `import firebase_admin` (in addition to any submodules like `firebase_admin.auth`) before calling `firebase_admin.initialize_app()`. Failure to do so will result in a `NameError`. Also, ensure `firebase-admin` is listed in your `requirements.txt`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Move resource-intensive initialization code to the global scope of your `main.py` file.","message":"To avoid 'cold start' performance issues, reuse expensive objects (like database connections, API clients, or large data structures) by declaring them as global variables outside of your function handler. They will be initialized once per container instance, rather than on every function invocation.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Double-check `requirements.txt` for all necessary packages, including `firebase-functions` and `firebase-admin`. Use `pip freeze > requirements.txt` in a clean virtual environment to capture exact versions.","message":"Ensure all Python package dependencies are correctly specified in `requirements.txt` within your functions directory. Missing or incorrect dependencies can lead to deployment failures or runtime errors in your deployed functions.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Set a global region via `options.set_global_options()` or specify `region` argument in the function decorator (e.g., `@https_fn.on_request(region='europe-west1')`).","message":"Deployment region needs to be explicitly specified for optimal performance and compliance. If not set, functions will deploy to the default `us-central1`. You can set a global region using `options.set_global_options(region=options.SupportedRegion.YOUR_REGION)` or per function.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}