{"id":18614854,"url":"https://github.com/andrewjbateman/python-functions-pubsub","last_synced_at":"2025-11-03T03:30:29.838Z","repository":{"id":96860875,"uuid":"395438053","full_name":"AndrewJBateman/python-functions-pubsub","owner":"AndrewJBateman","description":":clipboard: Google Cloud Functions used to send data using Python code to Google Cloud Pub/Sub where data can be published with a message","archived":false,"fork":false,"pushed_at":"2021-08-13T10:42:26.000Z","size":528,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-12-27T02:44:48.379Z","etag":null,"topics":["cloud-functions","pip3","pubsub","python3","subscriptions"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AndrewJBateman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-08-12T20:36:43.000Z","updated_at":"2021-08-13T10:44:59.000Z","dependencies_parsed_at":"2023-03-30T11:35:16.147Z","dependency_job_id":null,"html_url":"https://github.com/AndrewJBateman/python-functions-pubsub","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndrewJBateman%2Fpython-functions-pubsub","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndrewJBateman%2Fpython-functions-pubsub/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndrewJBateman%2Fpython-functions-pubsub/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndrewJBateman%2Fpython-functions-pubsub/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AndrewJBateman","download_url":"https://codeload.github.com/AndrewJBateman/python-functions-pubsub/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239406449,"owners_count":19633024,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloud-functions","pip3","pubsub","python3","subscriptions"],"created_at":"2024-11-07T03:27:13.427Z","updated_at":"2025-11-03T03:30:29.796Z","avatar_url":"https://github.com/AndrewJBateman.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# :zap: Python Functions Pub/Sub\n\n* Google Cloud Functions used to send data using Python code to Google Cloud Pub/Sub where data can be published with a message\n* Code from [D-I-Ry](https://www.youtube.com/channel/UCMHvK9tare9Y9O152C9wm3Q) with modifications - see [:clap: Inspiration](#clap-inspiration) below\n* **Note:** to open web links in a new window use: _ctrl+click on link_\n\n![GitHub repo size](https://img.shields.io/github/repo-size/AndrewJBateman/python-functions-pubsub?style=plastic)\n![GitHub pull requests](https://img.shields.io/github/issues-pr/AndrewJBateman/python-functions-pubsub?style=plastic)\n![GitHub Repo stars](https://img.shields.io/github/stars/AndrewJBateman/python-functions-pubsub?style=plastic)\n![GitHub last commit](https://img.shields.io/github/last-commit/AndrewJBateman/python-functions-pubsub?style=plastic)\n\n* [:zap: Python Functions Pub/Sub](#zap-python-functions-pubsub)\n  * [:page_facing_up: Table of contents](#page_facing_up-table-of-contents)\n  * [:books: General info](#books-general-info)\n  * [:camera: Screenshots](#camera-screenshots)\n  * [:signal_strength: Technologies](#signal_strength-technologies)\n  * [:floppy_disk: Setup](#floppy_disk-setup)\n  * [:computer: Code Examples](#computer-code-examples)\n  * [:cool: Features](#cool-features)\n  * [:clipboard: Status \u0026 To-do list](#clipboard-status--to-do-list)\n  * [:clap: Inspiration](#clap-inspiration)\n  * [:envelope: Contact](#envelope-contact)\n\n## :books: General info\n\n* Pub/Sub used to pass messages between services and to trigger Cloud Functions to run workflow\n* To subscribe to data in Cloud Pub/Sub, you create a subscription based on the topic, and subscribe to that, passing a callback function.\n* Python code deployed from VS Code terminal\n* Cloud Build API has to be enabled for deployment to work. Mine was already enabled from a similar previous project\n* From Pub/Sub factor-sensors topic is triggered by message published to pubsub factory sensors topic\n\n## :camera: Screenshots\n\n![screen print](./img/functions.png)\n![screen print](./img/pubsub.png)\n![screen print](./img/logs.png)\n\n## :signal_strength: Technologies\n\n* [Python v3](https://www.python.org/) programming language\n* [Python Cloud Client Libraries](https://cloud.google.com/python/docs/reference)\n* [JavaScript Object Notation - JSON](https://www.json.org/json-en.html) lightweight data-interchange format\n* [Google Cloud Functions](https://cloud.google.com/functions) functions as a service (FaaS) to run Python code\n* [Google Cloud Pub/Sub](https://cloud.google.com/pubsub) a fully-managed real-time messaging service that allows you to send and receive messages between independent applications.\n* [Google Cloud FireStore](https://cloud.google.com/firestore) fully managed, scalable, and serverless document database.\n\n## :floppy_disk: Setup\n\n* Ref. tutorial\n* When creating a Pub/Sub I found that the subscription was created automatically\n* `gcloud functions deploy automation_readings --runtime python39 --trigger-http --allow-unauthenticated` to deploy to Cloud Functions. Python code can be viewed in Cloud Functions `automation_readings` SOURCE menu. Message logs can be viewed under the LOGS menu. Logs can also be viewed in Firebase Console Logs menu.\n* `python sendMessage.py` to run `sendMessage.py`. This will trigger the Cloud Function using a http trigger URL and will supply sensor readings payload data in JSON format to the Cloud Functions Topic `automation_readings`. A response is returned with a status code. Clicking on 'PULL' in Cloud Pubsub Topic Messages will display message\n\n## :computer: Code Examples\n\n* `main.py` extract - to move data to Pubsub. Topic path copied from Cloud Pub/Sub Subscription Details/Topic name\n\n```python\n    topic_path = 'projects/python-pubsub-firestore/topics/factory-automation'\n\n    message_json = json.dumps({\n        'data': {'message': 'automation sensor readings'},\n        'readings': {\n            'sensorName': sensor_name,\n            'sensorReference': sensor_reference,\n            'temperature': temperature,\n            'humidity': humidity\n        }\n    })\n    message_bytes = message_json.encode('utf-8')\n\n    try:\n        publish_future = publisher.publish(topic_path, data=message_bytes)\n        publish_future.result() # verify that the publish succeeded\n    except Exception as e:\n        print(e)\n        return (e, 500)\n\n    return ('Message received and published to Pubsub', 200)\n```\n\n## :cool: Features\n\n* Cloud Pub/Sub decoupling senders and receivers, allowing secure and highly available communications between independently written applications.\n\n## :clipboard: Status \u0026 To-do list\n\n* Status: Working\n* To-do: Nothing\n\n## :clap: Inspiration\n\n* [D-I-Ry: Send data from Cloud Functions to PubSub in Python](https://www.youtube.com/watch?v=IjfRb5BKQaI)\n\n## :envelope: Contact\n\n* Repo created by [ABateman](https://github.com/AndrewJBateman), email: gomezbateman@yahoo.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrewjbateman%2Fpython-functions-pubsub","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandrewjbateman%2Fpython-functions-pubsub","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrewjbateman%2Fpython-functions-pubsub/lists"}