Library to create compute service with REST API and task queue
Project description
Compute Service
This is a Python library to create Compute Service with REST API and task queue.
Usage
To create new compute service one need to:
- Import packages
from pydantic import BaseModel
from compute_service import ComputeService
- Create service object with selected queue type:
service = ComputeService(queue='kafka')
kafka
and local
queue types are supported.
- Define model for input parameters and app factory:
class UserBase(BaseModel):
title: str
value: int
def create_app():
return service.create_app(UserBase)
- Define task processing callback and task handler:
def process(data):
print(f'Got data: {data}')
return {'ok': 'success'}
if __name__ == '__main__':
handler = service.create_handler(process)
handler.start()
- Start REST API:
uvicorn 'my_service:create_app'
- Start task handler:
python my_service.py
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
compute_service-0.0.1.tar.gz
(9.7 kB
view hashes)
Built Distribution
Close
Hashes for compute_service-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52e92940456f0a1688374d0eeacb37d0ee56587f188fd5cee0d0f38cff7f3a01 |
|
MD5 | fe00df7c95ee5d4b0674be937e09476c |
|
BLAKE2b-256 | 53e21bc2c3c87b1e9c6c66b7cb2159585467668ccffdb6d3c759223f659b8690 |