Skip to content

Rest-Utils provides simple generation of Restful APIs for database models defined using SQLAlchemy (or Flask-SQLAlchemy). The generated APIs send and receive messages in JSON format.

Notifications You must be signed in to change notification settings

windprog/rest-utils

Repository files navigation

Introduction

Rest-Utils 为使用 SQLAlchemy (or Flask-SQLAlchemy) 定义的数据库模型提供简单的Restful APIs生成。 生成的API以JSON格式转换数据。内部使用 marshmallow 使得复用数据转换非常简单。

For more information, see the

Install

# 可以从页面下载。不过推荐使用pip,virtualenv安装。
pip install Rest-Utils

Quick Start

pip install Rest-Utils flask_sqlalchemy
wget https://github.com/lerocha/chinook-database/raw/master/ChinookDatabase/DataSources/Chinook_Sqlite_AutoIncrementPKs.sqlite
import flask
from flask_sqlalchemy import SQLAlchemy
from rest_utils import APIManager

app = flask.Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///./Chinook_Sqlite_AutoIncrementPKs.sqlite'
db = SQLAlchemy(app)
api = APIManager(app, db=db)
api.auto_create()
app.run()
curl http://127.0.0.1:5000/api/Track?_num=20&_expand=1

详细使用参见:快速开始

Change Log

1.0.0

  • RESTful API风格,完整CRUD支持。
  • sqlachemy ORM 模型生成 marshmallow Schema and fields。
  • 从已有数据库自动生成API。

1.0.5

  • Change APIManager.auto_create to SQLAlchemy Automap.
  • 添加APIManager.register_admin.详情可参见:/example/auto_create_admin.py
  • add windows support

1.1.2 2018-05-24

  • 添加日志初始化方法
  • 支持marshmallow 2.15.0最新版

1.1.4

  • 添加 worker 存活性检测逻辑

1.2.1

  • 改变Schema check_existence默认为True,子资源跟随父资源的check_existence
  • 支持自增外检不填写更新: 通过lazy="dynamic" 的 relationship(AppenderQuery)过滤

TODO

About

Rest-Utils provides simple generation of Restful APIs for database models defined using SQLAlchemy (or Flask-SQLAlchemy). The generated APIs send and receive messages in JSON format.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages