Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Tempo de execução do Python
Visão geral
A função do Cloud Run é executada em um ambiente que consiste em uma versão do sistema
operacional, além de pacotes complementares, suporte a linguagens e a biblioteca
do Functions Framework que dá suporte e invoca a função.
Esse ambiente é identificado pela versão da linguagem e conhecido como ambiente de execução.
Para mais informações sobre tempos de execução em geral e para saber qual versão
do Ubuntu cada ambiente de execução Python usa, consulte o ambiente
de execução do Cloud Run functions.
Para começar a usar o Python nas funções do Cloud Run, consulte o
Guia de início rápido.
Selecionar o ambiente de execução
As funções do Cloud Run dão suporte a várias versões do Python, que estão listadas na
página Suporte ao ambiente de execução. Selecione
seu ambiente de execução Python preferencial para a função durante a implantação.
gcloud
Se você estiver usando a Google Cloud CLI, especifique o ambiente de execução usando o parâmetro --runtime. Por exemplo:
É possível preparar uma função diretamente do console do Google Cloud ou gravá-la na máquina local e fazer upload dela. Para preparar a máquina local para desenvolvimento do Python, consulte Como configurar um ambiente de desenvolvimento do Python.
Para começar rapidamente a usar o Python no Cloud Run functions, consulte o Guia de início rápido.
Estrutura do código-fonte
Para que as funções do Cloud Run encontrem a definição da sua função, seu código-fonte precisa seguir uma estrutura específica. Consulte
Como escrever funções do Cloud Run
para mais informações.
Como especificar dependências
Há duas maneiras de especificar dependências para o Cloud Run functions escritas
em Python: usando o arquivo requirements.txt do gerenciador de pacotes pip ou
o empacotamento de dependências locais junto com sua função. Para mais informações, consulte Como identificar dependências em Python.
O Cloud Run functions não dá suporte à especificação de dependências com
Pipfile/Pipfile.lock. Seu projeto não deve incluir esses arquivos.
Variáveis de ambiente
O ambiente de execução do Python define automaticamente certas variáveis de ambiente para que sua função use conforme necessário. Para detalhes, consulte
Como usar variáveis de ambiente.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-04-23 UTC."],[[["\u003cp\u003eCloud Run functions operate within a defined runtime environment that includes the operating system, language support, and the Functions Framework library.\u003c/p\u003e\n"],["\u003cp\u003eUsers can select their preferred Python runtime version during deployment through the Google Cloud CLI using the \u003ccode\u003e--runtime\u003c/code\u003e parameter or via the Google Cloud console.\u003c/p\u003e\n"],["\u003cp\u003ePython dependencies for Cloud Run functions can be managed through a \u003ccode\u003erequirements.txt\u003c/code\u003e file or by packaging them locally with the function.\u003c/p\u003e\n"],["\u003cp\u003eThe source code structure must adhere to specific guidelines to ensure Cloud Run functions can locate the function's definition.\u003c/p\u003e\n"],["\u003cp\u003ePython Environment variables will automatically be set by the runtime for the function to use.\u003c/p\u003e\n"]]],[],null,["# The Python Runtime\n==================\n\nOverview\n--------\n\nYour Cloud Run function runs in an environment consisting of an operating\nsystem version plus add-on packages, language support, and\nthe Functions Framework library that supports and invokes your function.\nThis environment is identified by the language version, and is known as the\nruntime.\n\nFor information about runtimes in general, and to learn which Ubuntu version\neach Python runtime uses, see the [Cloud Run functions execution\nenvironment](/functions/1stgendocs/concepts/execution-environment#python).\n\nTo get started with Python on Cloud Run functions, see the\n[Quickstart](/functions/1stgendocs/create-deploy-gcloud-1st-gen).\n\nSelect your runtime\n-------------------\n\nCloud Run functions supports several versions of Python, listed on the\n[Runtime support](/functions/1stgendocs/runtime-support#python) page. You can\nselect the preferred Python runtime for your function during deployment. \n\n### gcloud\n\nIf you're using the Google Cloud CLI, specify the runtime\nby using the `--runtime` parameter. For example: \n\n```bash\ngcloud functions deploy NAME --no-gen2 --runtime python312 --trigger-http\n```\n\nFor more deployment parameters, see [Deploy a Cloud Run functions](/functions/1stgendocs/deploy#basics).\n\n### Console\n\nIf you're using the Google Cloud console, see the\n[Google Cloud console instructions](/functions/1stgendocs/deploy#console).\n\nFunction preparation\n--------------------\n\nYou can prepare a function directly from the Google Cloud console or write it on\nyour local machine and upload it. To prepare your local machine for Python\ndevelopment, see [Setting Up a Python Development\nEnvironment](/python/docs/setup).\n\nTo get started quickly with Python on Cloud Run functions, see the\n[Quickstart](/functions/1stgendocs/create-deploy-http-python-1st-gen).\n\nSource code structure\n---------------------\n\nFor Cloud Run functions to find your function's definition, your\nsource code must follow a specific structure. See\n[Writing Cloud Run functions](/functions/1stgendocs/writing#structuring_source_code)\nfor more information.\n\nSpecifying dependencies\n-----------------------\n\nThere are two ways to specify dependencies for Cloud Run functions written\nin Python: using the `pip` package manager's `requirements.txt` file or\npackaging local dependencies alongside your function. For more information, see\n[Specifying dependencies in\nPython](/functions/1stgendocs/writing/specifying-dependencies-python).\n\nCloud Run functions doesn't support specifying dependencies with the\n`Pipfile/Pipfile.lock`. Your project shouldn't include these files.\n\nEnvironment variables\n---------------------\n\nYour Python runtime automatically sets certain environment variables for your\nfunction to use as needed. For details, see [Using Environment\nVariables](/functions/1stgendocs/configuring/env-var#python_37_and_go_111)."]]