{"id":22772306,"url":"https://github.com/pactflow/example-consumer-python-sns","last_synced_at":"2025-04-15T06:47:58.322Z","repository":{"id":105900058,"uuid":"529289392","full_name":"pactflow/example-consumer-python-sns","owner":"pactflow","description":"An SNS message consumer, written in Python, using Pact","archived":false,"fork":false,"pushed_at":"2025-04-05T07:15:50.000Z","size":103,"stargazers_count":3,"open_issues_count":2,"forks_count":1,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-04-15T06:47:53.677Z","etag":null,"topics":["example"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pactflow.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2022-08-26T14:26:59.000Z","updated_at":"2025-04-05T06:32:56.000Z","dependencies_parsed_at":null,"dependency_job_id":"7165f242-d35d-49c7-860f-5330a778a88e","html_url":"https://github.com/pactflow/example-consumer-python-sns","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/pactflow%2Fexample-consumer-python-sns","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pactflow%2Fexample-consumer-python-sns/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pactflow%2Fexample-consumer-python-sns/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pactflow%2Fexample-consumer-python-sns/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pactflow","download_url":"https://codeload.github.com/pactflow/example-consumer-python-sns/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249023707,"owners_count":21199958,"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":["example"],"created_at":"2024-12-11T17:08:03.140Z","updated_at":"2025-04-15T06:47:58.302Z","avatar_url":"https://github.com/pactflow.png","language":"Python","readme":"# Example Python AWS SNS Consumer\n\n[![Build Status](https://github.com/pactflow/example-consumer-python-sns/actions/workflows/build.yml/badge.svg)](https://github.com/pactflow/example-consumer-python-sns/actions)\n\n[![Can I deploy Status](https://test.pactflow.io/pacticipants/pactflow-example-consumer-python-sns/branches/main/latest-version/can-i-deploy/to-environment/production/badge.svg)](https://test.pactflow.io/pacticipants/pactflow-example-consumer-python-sns/branches/main/latest-version/can-i-deploy/to-environment/production/badge)\n\n[![Pact Status](https://test.pactflow.io/pacts/provider/pactflow-example-provider-python-sns/consumer/pactflow-example-consumer-python-sns/latest/badge.svg?label=consumer)](https://test.pactflow.io/pacts/provider/pactflow-example-provider-python-sns/consumer/pactflow-example-consumer-python-sns/latest) (latest pact)\n\n[![Pact Status](https://test.pactflow.io/matrix/provider/pactflow-example-provider-python-sns/latest/main/consumer/pactflow-example-consumer-python-sns/latest/main/badge.svg?label=consumer)](https://test.pactflow.io/pacts/provider/pactflow-example-provider-python-sns/consumer/pactflow-example-consumer-python-sns/latest/prod) (prod/prod pact)\n\nThis is an example of a Python AWS SNS consumer that uses Pact, [Pactflow](https://pactflow.io) and GitHub Actions to ensure that it is compatible with the expectations its consumers have of it.\n\nAll examples in the series `example-consumer-\u003clanguage\u003e-sns` provide the same functionality to be easily comparable across languages.\nAs such, please refer to [https://docs.pactflow.io/docs/examples/aws/sns/consumer/](AWS SNS Consumer Examples) to avoid unnecessary duplication of details here.\n\nLanguage specific sections which differ from the canonical example only can be found below.\n\n### How to write tests?\n\nWe recommend that you split the code that is responsible for handling the protocol specific things - in this case the lambda and SNS input - and the piece of code that actually handles the payload.\n\nYou're probably familiar with layered architectures such as Ports and Adaptors (also referred to as a Hexagonal architecture). Following a modular architecture will allow you to do this much more easily:\n\n![Code Modularity](docs/ports-and-adapters.png \"Code Modularity\")\n\nThis code base is setup with this modularity in mind:\n\n- [Lambda Handler](src/_lambda/product.py)\n- [Event Service](src/product/product_service.py)\n- Business Logic\n  - [Product](src/product/product.py)\n  - [Repository](src/product/product_repository.py)\n\nThe target of our [consumer pact test](tests/unit/product_service_pact_test.py) is the [Event Service](src/product/product_service.py), which is responsible for consuming a Product update event, and persisting it to a database (the Repository).\n\nSee also:\n\n- https://dius.com.au/2017/09/22/contract-testing-serverless-and-asynchronous-applications/\n- https://dius.com.au/2018/10/01/contract-testing-serverless-and-asynchronous-applications---part-2/\n\n## Usage\n\n### Testing\n\n- Run the unit tests: `make test`\n- Run a (local) lambda integration test: `make integration`","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpactflow%2Fexample-consumer-python-sns","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpactflow%2Fexample-consumer-python-sns","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpactflow%2Fexample-consumer-python-sns/lists"}