- python3.5
- asyncio
Обработка урлов вида
- /v1/get - get_v1 - сообщение в сентри об использовании устаревшего метода
- /v2/get - get
uwsgi --http :9090 --wsgi-file app.py
python3.5 app.py --async
python3.5 app.py --consumer
Обработка урлов вида
uwsgi --http :9090 --wsgi-file app.py
python3.5 app.py --async
python3.5 app.py --consumer
| # для инциалищации | |
| from example import views # noqa | |
| from cianlib import Runner | |
| runner = Runner(version=2) | |
| # для wsgi | |
| application = runner.wsgi_application # noqa | |
| runner.maybe_run() # asyncio, consumer run |
| from cian.entities import Entity, attrs | |
| class ExampleEntity(Entity): | |
| id = attrs.UnsignedInteger(help='ID') | |
| title = attrs.String(help='Название') | |
| image_url = attrs.String(help='URL картинки') | |
| object_count = attrs.Integer(help='Количество объектов') |
| from cianlib.schemas import fields, Schema, EntitySchema | |
| from exmaple.entities import ExampleEntity | |
| class RequestSchema(Schema): | |
| user_id = fields.Integer(required=True, min=1, help='ID пользователя') | |
| limit = fields.Integer(required=True, min=0, help='Лимит') | |
| offset = fields.Integer(required=True, min=0, help='Оффсет') | |
| class ResponseSchemaOld(EntitySchema): | |
| class Meta: | |
| entity = ExampleEntity | |
| lowercase = True |
| from cianlib import api | |
| from cianlib.schemas import EntitySchema | |
| from example.schemas import RequestSchema, ResponseSchemaOld | |
| from exmaple.entities import ExampleEntity | |
| @api.get(RequestSchema, EntitySchema.by(ExampleEntity)) | |
| def get(params): | |
| yield from asyncio.sleep(3) | |
| return ExampleEntity( | |
| id=3, | |
| title='Название', | |
| image_url='http://google.com/logo.png', | |
| object_count=3 | |
| ) | |
| @api.get(RequestSchema, ResponseSchemaOld) | |
| def get_v1(params): | |
| yield from asyncio.sleep(3) | |
| return ExampleEntity( | |
| id=3, | |
| image_url='http://google.com/logo.png', | |
| object_count=3 | |
| ) |