Catalant核心API框架
ct-core-api的Python项目详细描述
ct核心api–catalant核心api框架。
此框架使开发人员能够轻松构建和测试公开restful api的flask web应用程序。
它由许多python库和项目组成,最显著的是:
web框架
数据库/orm
对象序列化
- 棉花糖–2.10
- http://marshmallow.readthedocs.io/en/latest/
- 烧瓶棉花糖–0.7
- https://flask-marshmallow.readthedocs.io/en/latest/
- 棉花糖炼金术–0.12
- http://marshmallow-sqlalchemy.rtfd.org/
rest/swagger
- swagger(openapi规范)
- https://github.com/OAI/OpenAPI-Specification
- swagger用户界面
- https://github.com/swagger-api/swagger-ui
- 盛满烧瓶–0.3
- http://flask-restful.readthedocs.io/en/0.3.1/
- API规范–0.16
- http://apispec.rtfd.org/
身份验证/授权
- oauthlib–2.0
- http://oauthlib.rtfd.org/)
- 烧瓶OAuthlib–0.9
- http://flask-oauthlib.rtfd.org/
- 烧瓶登录–0.3
- http://flask-login.rtfd.org/
- 权限–0.4
- https://github.com/hustlzp/permission
- bcrypt–3.1
- https://github.com/pyca/bcrypt/
分布式内存缓存
- memcached
- https://memcached.org/
- 堆缓存–0.6
- http://dogpilecache.readthedocs.io/en/latest/usage.html
- 烧瓶堆缓存–0.2
- https://bitbucket.org/ponomar/flask-dogpile-cache
分布式任务队列
- rabbitmq
- https://www.rabbitmq.com/
- 芹菜–3.1
- http://www.celeryproject.org/
要求
- Python2.6+,3.3+/pypy2(2.5.0)
用法
请参阅Demo API Application以获得一个完整的运行示例,该示例演示 框架组件。
开始
这是如何在项目中创建和注册api的方法:
"""catalant/example/app/__init__.py""" from ct_core_api.api import core from ct_core_api.api.app import create_api_app # TODO: Revise this example for 2.0
以下是应用程序的主要入口点应该是什么样子:
"""catalant/example/app/main.py""" #!/usr/bin/env python from catalant.example.app import create_example_api_app app = create_example_api_app() if __name__ == '__main__': from ct_core_api.api.app import runner runner.run(app)
这样构造入口点就允许我们以可执行脚本的形式调用和运行flask应用程序, 直接使用flask的开发服务器,或者使用uwsgi web服务器。
变更日志
每个api应用程序都有自己的变更日志。开发人员需要在任何时候更新变更日志 API发生结构变化。
“Keep a CHANGELOG”对于何时以及如何维护变更日志有一套很好的指导原则。
默认情况下,api的变更日志可以在/changelog处访问,条目位于 应用程序的根文件夹(apiapp.root_path)。
You can modify the path to this file using the API_CHANGELOG_PATH config setting.
格式
变更日志文件使用以下yaml格式:
--- # Separate changelog entries by date <yyyy-mm-dd>: # The current date <added|changed|removed|deprecated>: # The type of change - type: <operation|parameter|model|enum>: # What kind of thing changed id: <identifier> # The changed thing's identifier [note]: <note> # An optional, human-friendly note of what changed
图例
- 操作
- 版本化的端点操作
- 参数
- 一个或多个端点操作的输入参数
- 型号
- 一个或多个端点操作的响应模型
- 枚举
- 一个或多个输入参数用于表示选项列表的枚举
贡献
ct核心api的开发发生在github:https://github.com/catalant/ct-core-api
包装布局
此存储库中的包经过精心组织,以避免循环导入并保持适当的分隔 令人担忧。 从软件包中导入和使用模块是安全的,只要它们不违反下面描述的顺序:
- ct_core_api.common
- ct_core_api.core
- ct_core_api.api.lib
- ct_core_api.api.common
- ct_core_api.api.core
- ct_core_api.api.app
您的模块可以引用相同包中的其他模块或相同级别或更高级别包中的。 根据这份名单。例如,ct_core_api.api.core中的模块可以依赖于 ct_core_api.api.common,但不是来自ct_core_api.api.app的。
烟雾测试
下面是如何运行虚拟应用程序来验证核心api和web应用程序的基本功能:
可执行的python脚本:
export PYTHONPATH=$PYTHONPATH:`pwd` ./ct_core_api/_main.py
烧瓶开发服务器:
export FLASK_APP=ct_core_api/_main.py export FLASK_DEBUG=1 export FLASK_CONFIG=development flask run
贡献者
- jcrafford(贾斯汀·克拉福德)
许可证
根据MIT license授权。