Skip to main content

A web framework that is composed of flask, pydantic, and openapi 3.

Project description

Cibo

Python Version System Platform Travis CI Coverage Code style: black License Repo Size

Installing

python setup.py install

A Simple Example

from cibo import Handler, SimpleContext, Blueprint, BaseApiQuery, BaseApiBody

api = Blueprint("api")

@api.post("/echo")
class EchoHandler(Handler):

    decorators = [token_auth]

    class Query(BaseApiQuery):
        a: str
        b: Optional[List[int]]
        c: Optional[Dict[str, int]]

    class Body(BaseApiBody):
        d: Set[int]
        e: Tuple[Dict[int, List], Dict[int, List]]

    def handle(self, context: SimpleContext, query: Query, body: Body):
        """echo the recevied params"""
        return context.success(
            data=f"a: {query.a}, b: {query.b}, c: {query.c}, d: {body.d}, e: {body.e}"
        )

Use a custom model and validate function

@api.post("/user")
class UserHandler(Handler):
    class Body(BaseApiBody):
        class User(BaseModel):
            name: str = Field(description="姓名")
            emails: Optional[List[str]] = Field(description="邮箱")

            @classmethod
            def validate(cls, value: Any):
                obj = cls(**value)
                if obj.emails:
                    if not all(
                        [
                            re.match(
                                r"^[0-9a-zA-Z_]{0,19}@[0-9a-zA-Z]{1,13}\.[com,cn,net]{1,3}$", email
                            )
                            for email in obj.emails
                        ]
                    ):
                        raise ValueError("email is not valid")
                return obj

        user: User
        inviter: str

    def handle(self, context: SimpleContext, body: Body):
        """custom model and validate"""
        return context.success(user=body.user, inviter=body.inviter)

Dev

pull stubs files

git submodule update --init --recursive

Docs

http://127.0.0.1:5000/docs

Contributing Guide

First time setup

Create a virtual environment and install requirements:

$ python3 -m venv env
$ source env/bin/activate
$ python -m pip install --upgrade pip setuptools
$ pip install -r requirements/dev.txt
$ pip install -e .
$ pre-commit install

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

cibo-0.0.2.tar.gz (15.2 kB view details)

Uploaded Source

File details

Details for the file cibo-0.0.2.tar.gz.

File metadata

  • Download URL: cibo-0.0.2.tar.gz
  • Upload date:
  • Size: 15.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.7.5

File hashes

Hashes for cibo-0.0.2.tar.gz
Algorithm Hash digest
SHA256 9a18b7fe2db29d0648b01e0bde67f679ff655ba98e4daa5edacb58cb07df2c6d
MD5 078c2729ec99c2c74b54f80d1311615d
BLAKE2b-256 1519ca6cc8746fac09833f590a0e4ff6f5ce80fadbc10d63a26ba0a57deca86b

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