Chilo is a lightweight, form-meets-function, opinionated (yet highly configurable) api framework
Chilo, short for chilorhinophis (meaning two headed snake), is a lightweight, form-meets-function, opinionated (yet highly configurable) api framework.
- No route definitions needed; route based on your directory structure
- Built-in OpenAPI request and response validation
- Built-in GRPC support
- Generate OpenAPI spec from code base
- Ease of use with gunicorn
- Infinitely customizable with middleware extensions
The Chilo philosophy is to provide a dry, configurable, declarative framework, which encourages Happy Path Programming (HPP).
Happy Path Programming is a development approach where all inputs are validated up front, allowing the main logic to proceed without interruption. This avoids deeply nested conditionals, scattered try/catch blocks, and the clutter of mid-flow exception handling. Chilo provides a flexible middleware system that lets developers define what counts as valid input—keeping the code focused, readable, and on the "happy path" where things work as expected.
$ pip install chilo_api
# pipenv install chilo_api
# poetry add chilo_apifrom chilo_api import Chilo
api = Chilo(
base_path='/',
handlers='api/handlers',
){PWD}/api/handlers/__init__.py
from chilo_api import Request, Response
def get(request: Request, response:Response ) -> Response:
response.body = {'hello': 'world'}
return responsepython -m chilo_api serve --api=main --reload=truefrom chilo_api import requirements
@requirements(required_params=['greeting'])
def get(request, response):
response.body = {'hello': request.query_params['greeting']}
return responsehttp://127.0.0.1:3000/?greeting=developer
from chilo_api import Chilo
api = Chilo(
api_type='grpc',
handlers='api/handlers',
protobufs='api/protobufs',
reflection=True,
port=50051
)syntax = "proto3";
package calculator;
service Calculator {
rpc Add(CalcRequest) returns (CalcResponse);
rpc Subtract(CalcRequest) returns (CalcResponse);
rpc Multiply(CalcRequest) returns (CalcResponse);
rpc Divide(CalcRequest) returns (CalcResponse);
}
message CalcRequest {
double num1 = 1;
double num2 = 2;
}
message CalcResponse {
double result = 1;
}{PWD}/api/handlers/__init__.py
from chilo_api import requirements, Request, Response
@requirements(
protobuf='calculator.proto',
service='Calculator',
rpc='Add'
)
def add(request: Request, response: Response) -> Response:
num1 = request.body.get('num1', 0)
num2 = request.body.get('num2', 0)
result = num1 + num2
response.body = {'result': result}
return responsepython -m chilo_api serve --api=main_grpc