1

In order to use auto-completion for Python in vscode I type-annotate my functions parameters:

A google-cloud-function when triggered has the following type signature:

from google.cloud import functions_v1

def my_function(data: Dict[Text, Any],
                context: functions_v1.context.Context) -> None:
    ...

Is it possible to install the google.cloud.functions_v1 package?

Checked on the gcloudpypi page and there is no package available.

3 Answers 3

3

Unfortunately this is not currently possible. I've filed an internal feature request to open-source these types as a google-cloud-functions package, and will update this answer if/when this happens.

Sign up to request clarification or add additional context in comments.

1 Comment

Is it possible to typehint this at all ? I installed the package that you've referenced there and don't see a way to type hint it still, from google.cloud import functions_v1 doesn't have functions_v1.context.Context
2

I found this library: functions-framework on GoogleCloudPlatform/functions-framework-python github repository.

As it is a namespace package, you can import it by using the following snippet:

$ pip install functions-framework
...
$ pip freeze | grep functions-framework
functions-framework==2.1.3
$ python
>>> import google.cloud.functions.context
>>> google.cloud.functions.context.Context
<class 'google.cloud.functions_v1.context.Context'>

So for your code:

import google.cloud.functions.context as functions_context

def my_function(data: Dict[Text, Any],
                context: functions_context.Context) -> None:
    ...

Comments

0

You can install the Google Cloud Functions API client library via pypi

https://pypi.org/project/google-cloud-functions/

I can then access the functions_v1 type annotation and function attributes in my editor which is PyCharm here:

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.