Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

Generating google-events-cloud and google-events-firebase

The program generate-from-proto.py will fetch the Google Cloudevents proto files from a Github repository and generate Python libraries for each type of event defined there.

Before running the generator, create a virtual Python environment (recommended) and install the libraries it needs with:

pip install -r requirements.txt

You will also need an Internet connection as the generator fetches the event definitions from Github.

Code generator usage: python generate-from-proto.py [arguments]

Arguments are:

-h or --help
Print help and then exit without other action.
-q or --quiet
If specified, do not prompt for confirmation of any operation, including ones that would delete files or directories.
-o [dirname] or --out [dirname]
Required. Write generated library source code to dirname. That directory, and all its contents, will be deleted first. Program will prompt user for confirmation before deleting any contents, unless -q or --quite is specified.
-r [repo-name] or --repo [repo-name]
Optional. Fetch proto definitions from Github repo repo-name. Default, if not specified, is googleapis/google-cloudevents.
-b [branch-name] or --out [branch-name]
Optional. Fetch proto definitions from Github branch branch-name. Default, if not specified, is main.

Installing the generated libraries

The generated code can be packaged and installed using standard Python packaging tools. Or, the library can be installed directly from source by changing to the generated code library and running:

pip install .

Sample code using the libraries

Print the name of the bucket and object that triggered the event:

from google.events.cloud import storage

with open("file-containing-storage-json-example", "r") as f:
    example = f.read()

event = storage.StorageObjectData.from_json(example)
print(f"Bucket is {event.bucket}")
print(f"Name is {event.name}")