Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/andrewthetechie/pydantic-sqs
Send and receive Pydantic models with AWS SQS
https://github.com/andrewthetechie/pydantic-sqs
Last synced: about 1 month ago
JSON representation
Send and receive Pydantic models with AWS SQS
- Host: GitHub
- URL: https://github.com/andrewthetechie/pydantic-sqs
- Owner: andrewthetechie
- License: other
- Created: 2022-10-31T23:59:40.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-30T12:30:53.000Z (8 months ago)
- Last Synced: 2024-05-04T00:25:25.587Z (8 months ago)
- Language: Python
- Homepage:
- Size: 594 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 24
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.rst
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.rst
Awesome Lists containing this project
- awesome-pydantic - pydantic-sqs - Send and receive pydantic models via AWS SQS (Object Mapping)
- awesome-pydantic - pydantic-sqs - Send and receive pydantic models via AWS SQS (Object Mapping)
README
# pydantic-sqs
Convert your pydantic models to and from AWS SQS messages.
## Main Dependencies
- [Python +3.7](https://www.python.org)
- [pydantic](https://github.com/samuelcolvin/pydantic/)
- [aiobotocore](https://github.com/aio-libs/aiobotocore)## Getting Started
```python
from pydantic_sqs import SQSModel, SQSQueue
from pydantic import Field
import asyncio
from pprint import pprint
import osclass ThisModel(SQSModel):
foo: str = Field(..., description="Foo")class ThatModel(SQSModel):
bar: str = Field(..., description="bar")async def main():
queue_kwargs = {
"queue_url": os.environ.get("SQS_QUEUE_URL"),
"endpoint_url": os.environ.get("SQS_ENDPOINT_URL", None),
"use_ssl": os.environ.get("SQS_USE_SSL", "true").lower() == "true",
}
if queue_kwargs["endpoint_url"] is None:
del queue_kwargs["endpoint_url"]queue = SQSQueue(**queue_kwargs)
queue.register_model(ThisModel)
queue.register_model(ThatModel)this_thing = ThisModel(foo="1234")
that_thing = ThatModel(bar="5678")
await this_thing.to_sqs()
await that_thing.to_sqs()new_things = await queue.from_sqs(max_messages=10, wait_time_seconds=90)
pprint(new_things)
for thing in new_things:
await thing.delete_from_queue()print("deleted all the messages we got from the queue")
pprint(new_things)if __name__ == "__main__":
asyncio.run(main())
```### Examples
Examples are in the [examples/](./examples) directory of this repo.
### Installation
Install the package
pip install pydantic-sqs
## Contributing
Contributions are very welcome.
To learn more, see the [Contributor Guide](./CONTRIBUTING.rst)## License
Licensed under the [MIT License](./LICENSE)