Skip to content

QUICK START

Install using pip:

$ pip install "propan[async-redis]"
---> 100%

Tip

To start a new project we need a test broker container

docker run -d --rm -p 6379:6379 --name test-mq redis

$ pip install "propan[async-rabbit]"
---> 100%

Tip

To start a new project we need a test broker container

docker run -d --rm -p 5672:5672 --name test-mq rabbitmq

$ pip install "propan[async-kafka]"
---> 100%

Tip

To start a new project we need a test broker container

docker run -d --rm -p 9092:9092 --name test-mq \
-e KAFKA_ENABLE_KRAFT=yes \
-e KAFKA_CFG_NODE_ID=1 \
-e KAFKA_CFG_PROCESS_ROLES=broker,controller \
-e KAFKA_CFG_CONTROLLER_LISTENER_NAMES=CONTROLLER \
-e KAFKA_CFG_LISTENERS=PLAINTEXT://:9092,CONTROLLER://:9093 \
-e KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT \
-e KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://127.0.0.1:9092 \
-e KAFKA_BROKER_ID=1 \
-e KAFKA_CFG_CONTROLLER_QUORUM_VOTERS=1@kafka:9093 \
-e ALLOW_PLAINTEXT_LISTENER=yes \
bitnami/kafka

$ pip install "propan[async-sqs]"
---> 100%

Tip

To start a new project we need a test broker container

docker run -d --rm -p 9324:9324 --name test-mq softwaremill/elasticmq-native

$ pip install "propan[async-nats]"
---> 100%

Tip

To start a new project we need a test broker container

docker run -d --rm -p 4222:4222 --name test-mq nats -js

Basic usage

To create a basic application, add the following code to a new file (e.g. serve.py):

serve.py
1
2
3
4
5
6
7
8
9
from propan import PropanApp, RedisBroker

broker = RedisBroker("redis://localhost:6379")

app = PropanApp(broker)

@broker.handle("test")
async def base_handler(body):
    print(body)
serve.py
1
2
3
4
5
6
7
8
9
from propan import PropanApp, RabbitBroker

broker = RabbitBroker("amqp://guest:guest@localhost:5672/")

app = PropanApp(broker)

@broker.handle("test")
async def base_handler(body):
    print(body)
serve.py
1
2
3
4
5
6
7
8
9
from propan import PropanApp, KafkaBroker

broker = KafkaBroker("localhost:9092")

app = PropanApp(broker)

@broker.handle("test")
async def base_handler(body):
    print(body)
serve.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
from botocore import UNSIGNED
from aiobotocore.config import AioConfig
from propan import PropanApp, SQSBroker

broker = SQSBroker(
    url="http://localhost:9324",
    region_name="us-west-2",
    config = AioConfig(signature_version=UNSIGNED)
)

app = PropanApp(broker)

@broker.handle("test")
async def base_handler(body):
    print(body)
serve.py
1
2
3
4
5
6
7
8
9
from propan import PropanApp, NatsBroker

broker = NatsBroker("nats://localhost:4222")

app = PropanApp(broker)

@broker.handle("test")
async def base_handler(body):
    print(body)

And just run this command:

$ propan run serve:app

2023-04-10 23:39:41,145 INFO     - Propan app starting...
2023-04-10 23:39:41,151 INFO     - `base_handler` waiting for messages
2023-04-10 23:39:41,152 INFO     - Propan app started successfully! To exit press CTRL+C

Project template

Propan CLI is able to generate a production-ready application template:

$ propan create async [broker] [projectname]
Create Propan project template at: /home/user/projectname

Note

Project template requires pydantic[dotenv] installation to run

Just run the created project:

### Run broker first
$ docker compose --file [projectname]/docker-compose.yaml up -d [broker]

### Run project
$ propan run [projectname].app.serve:app --env=.env --reload

2023-04-10 23:39:41,140 INFO     - Started reloader process [115536] using WatchFiles
2023-04-10 23:39:41,145 INFO     - Propan app starting...
2023-04-10 23:39:41,151 INFO     - `base_handler` waiting for messages
2023-04-10 23:39:41,152 INFO     - Propan app started successfully! To exit press CTRL+C

Enjoy your new development experience!

Don't forget to stop the test broker container
docker container stop test-mq