https://github.com/conradwt/eventstore-using-python-client-from-docker-compose
https://github.com/conradwt/eventstore-using-python-client-from-docker-compose
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/conradwt/eventstore-using-python-client-from-docker-compose
- Owner: conradwt
- Created: 2024-09-06T07:08:42.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-07T11:02:45.000Z (almost 2 years ago)
- Last Synced: 2024-09-08T12:06:25.537Z (almost 2 years ago)
- Language: Python
- Size: 19.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Python Sample: Hello, World!
This guide shows you how to stand up a sample Hello World application, built with [Flask](https://flask.palletsprojects.com/en/3.0.x/), that connects to EventStoreDB.
The sample exposes a simple HTTP endpoint `http://localhost:8080/hello-world?visitor={visitor}` that shows how to append to and read from a stream in EventStoreDB.
When a visitor says hello via `hello-world?visitor={visitor}`, an event is appended to a stream to record the fact they have been greeted.
The stream is then read from beginning to end to return the full log of visitors on each call to `/hello-world?visitor={visitor}`.
You can see how this is done in the source code [here](./main.py).
## Getting Started
## Software requirements
- Docker Desktop 4.34.0 or newer
- Python 3.12 or newer
Note: This tutorial was updated on macOS 14.6.1.
## Running The Sample
1. clone the repository:
```
git clone https://github.com/conradwt/eventstore-using-python-client-from-docker-compose.git
cd eventstore-using-python-client-from-docker-compose
```
2. create development.env file
```zsh
cp development.env.example development.env
```
3. run the client application and database using Docker Compose
```
docker compose up -d
```
4. verify the containers are up and running
```zsh
docker compose ps
```
The results should look something like the following:
```text
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
eventstore-using-python-client-from-docker-compose-app-1 esdb-sample-python "gunicorn -w 4 -b 0.…" app 2 minutes ago Up About a minute 0.0.0.0:8080->8080/tcp
node1.eventstore eventstore/eventstore:24.6.0-alpha-arm64v8 "/opt/eventstore/Eve…" node1.eventstore 11 seconds ago Up 10 seconds (healthy) 1112-1113/tcp, 0.0.0.0:2111->2113/tcp
node2.eventstore eventstore/eventstore:24.6.0-alpha-arm64v8 "/opt/eventstore/Eve…" node2.eventstore 11 seconds ago Up 10 seconds (healthy) 1112-1113/tcp, 0.0.0.0:2112->2113/tcp
node3.eventstore eventstore/eventstore:24.6.0-alpha-arm64v8 "/opt/eventstore/Eve…" node3.eventstore 11 seconds ago Up 10 seconds (healthy) 1112-1113/tcp, 0.0.0.0:2113->2113/tcp
```
5. test the application:
Say hello as `Ouro`:
```zsh
curl "localhost:8080/hello-world?visitor=Ouro"
```
The results should look something like the following:
```text
1 visitors have been greeted, they are: [Ouro]
```
Say hello as `YourName`:
```zsh
curl "localhost:8080/hello-world?visitor=YourName"
```
The results should look something like the following:
```text
2 visitors have been greeted, they are: [Ouro, YourName]
```
6. stop and remove the containers
```zsh
docker compose down
```
## Additional Information
For more in-depth and detailed examples of using EventStoreDB and the Python Client, refer to:
- EventStoreDB: [Getting Started With EventStoreDB](https://developers.eventstore.com/clients/grpc/)
- Python Client: [Python Client Samples](https://github.com/pyeventsourcing/esdbclient/tree/1.0)