Skip to main content

Chilo is a lightweight, form-meets-function, opinionated (yet highly configurable) api framework.

Project description

Chilo

Chilo

Chilo is a lightweight, form-meets-function, opinionated (yet highly configurable) api framework

CircleCI Quality Gate Status Coverage Bugs pypi package python Inline docs contributions welcome

Chilo, short for chilorhinophis (meaning two headed snake), is a lightweight, form-meets-function, opinionated (yet highly configurable) api framework.

Benefits

  • 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

Philosophy

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.

Documentation & Examples

Quick Start (REST)

0. Install

$ pip install chilo_api
# pipenv install chilo_api
# poetry add chilo_api

1. Create main.py for REST

from chilo_api import Chilo


api = Chilo(
    base_path='/',
    handlers='api/handlers',
)

2. Create First Handler

{PWD}/api/handlers/__init__.py

from chilo_api import Request, Response

def get(request: Request, response:Response ) -> Response:
    response.body = {'hello': 'world'}
    return response

3. Run your API

python -m chilo_api serve --api=main --reload=true

4. Checkout your API

http://127.0.0.1:3000/

5. Validate Your Endpoint (optional)

from chilo_api import requirements


@requirements(required_params=['greeting'])
def get(request, response):
    response.body = {'hello': request.query_params['greeting']}
    return response

6. Checkout your API (again)

http://127.0.0.1:3000/?greeting=developer

Quick Start (GRPC)

1. Create main_grpc.py for GRPC

from chilo_api import Chilo


api = Chilo(
    api_type='grpc',
    handlers='api/handlers',
    protobufs='api/protobufs',
    reflection=True,
    port=50051
)

2. Create Your Protobuff files

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;
}

3. Create First GRPC Handlers

{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 response

4. Run your GRPC API

python -m chilo_api serve --api=main_grpc

5. Checkout your GRPC API

http://127.0.0.1:50051/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chilo_api-2.0.0b4.tar.gz (78.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

chilo_api-2.0.0b4-py3-none-any.whl (107.9 kB view details)

Uploaded Python 3

File details

Details for the file chilo_api-2.0.0b4.tar.gz.

File metadata

  • Download URL: chilo_api-2.0.0b4.tar.gz
  • Upload date:
  • Size: 78.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.17

File hashes

Hashes for chilo_api-2.0.0b4.tar.gz
Algorithm Hash digest
SHA256 5a4dab9951556e5c66ff1d4f9ca1dcf941b2e30c5f867e7ea766e153a85b7482
MD5 6416f44b51d747335c8fb03b9bcd1692
BLAKE2b-256 46bc7736fbeac27de5d64bf2fd76b08b20708b4aba531d3ac7f8cd37ec0f112d

See more details on using hashes here.

File details

Details for the file chilo_api-2.0.0b4-py3-none-any.whl.

File metadata

  • Download URL: chilo_api-2.0.0b4-py3-none-any.whl
  • Upload date:
  • Size: 107.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.17

File hashes

Hashes for chilo_api-2.0.0b4-py3-none-any.whl
Algorithm Hash digest
SHA256 ba3d0cb3010859b9de8f28616d54fdbeeb8c9245976b808cdd7ebb3e46783f1c
MD5 317d013a468aba6ece90dcd1df560be8
BLAKE2b-256 b9a4899803cdef8d87d6456c22ee7c9e24629e3f16699af584b0d8a6b4beeeb7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page