当前位置: 首页 > 软件库 > Web应用开发 > Web框架 >

eve-sqlalchemy

SQLAlchemy data layer for Eve-powered RESTful APIs
授权协议 View license
开发语言 Python
所属分类 Web应用开发、 Web框架
软件类型 开源软件
地区 不详
投 递 者 江阳羽
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

Eve-SQLAlchemy extension

Powered by Eve, SQLAlchemy and good intentions this extension allowsto effortlessly build and deploy highly customizable, fully featuredRESTful Web Services with SQL-based backends.

Eve-SQLAlchemy is simple

The following code blocks are excerpts of examples/one_to_many and shouldgive you an idea of how Eve-SQLAlchemy is used. A complete working example canbe found there. If you are not familiar with Eveand SQLAlchemy, it is recommended to read upon them first.

For this example, we declare two SQLAlchemy mappings (from domain.py):

class Parent(BaseModel):
    __tablename__ = 'parent'
    id = Column(Integer, primary_key=True)
    children = relationship("Child")

class Child(BaseModel):
    __tablename__ = 'child'
    id = Column(Integer, primary_key=True)
    parent_id = Column(Integer, ForeignKey('parent.id'))

As for Eve, a settings.py is used to configure our API. Eve-SQLAlchemy,having access to a lot of metadata from your models, can automatically generatea great deal of the DOMAIN dictionary for you:

DEBUG = True
SQLALCHEMY_DATABASE_URI = 'sqlite://'
SQLALCHEMY_TRACK_MODIFICATIONS = False
RESOURCE_METHODS = ['GET', 'POST']

DOMAIN = DomainConfig({
    'parents': ResourceConfig(Parent),
    'children': ResourceConfig(Child)
}).render()

Finally, running our application server is easy (from app.py):

app = Eve(validator=ValidatorSQL, data=SQL)

db = app.data.driver
Base.metadata.bind = db.engine
db.Model = Base

# create database schema on startup and populate some example data
db.create_all()
db.session.add_all([Parent(children=[Child() for k in range(n)])
                    for n in range(10)])
db.session.commit()

# using reloader will destroy the in-memory sqlite db
app.run(debug=True, use_reloader=False)

The API is now live, ready to be consumed:

$ curl -s http://localhost:5000/parents | python -m json.tool
{
    "_items": [
        {
            "_created": "Sun, 22 Oct 2017 07:58:28 GMT",
            "_etag": "f56d7cb013bf3d8449e11e8e1f0213f5efd0f07d",
            "_links": {
                "self": {
                    "href": "parents/1",
                    "title": "Parent"
                }
            },
            "_updated": "Sun, 22 Oct 2017 07:58:28 GMT",
            "children": [],
            "id": 1
        },
        {
            "_created": "Sun, 22 Oct 2017 07:58:28 GMT",
            "_etag": "dd1698161cb6beef04f564b2e18804d4a7c4330d",
            "_links": {
                "self": {
                    "href": "parents/2",
                    "title": "Parent"
                }
            },
            "_updated": "Sun, 22 Oct 2017 07:58:28 GMT",
            "children": [
                1
            ],
            "id": 2
        },
        "..."
    ],
    "_links": {
        "parent": {
            "href": "/",
            "title": "home"
        },
        "self": {
            "href": "parents",
            "title": "parents"
        }
    },
    "_meta": {
        "max_results": 25,
        "page": 1,
        "total": 10
    }
}

All you need to bring your API online is a database, a configurationfile (defaults to settings.py) and a launch script. Overall, youwill find that configuring and fine-tuning your API is a very simpleprocess.

Eve-SQLAlchemy is thoroughly tested under Python 2.7-3.7 and PyPy.

Documentation

The offical project documentation can be accessed ateve-sqlalchemy.readthedocs.org. For full working examples,especially regarding different relationship types, see the examplesdirectory in this repository.

 相关资料
  • Eve

    Eve 是一款Python的REST API框架,用于发布高可定制的、全功能的 RESTful 的 Web 服务。 特定: 强调REST 非常全面的CRUD操作 可自定义的资源端点 自定义多个项目端点 筛选和排序 分页 HATEOAS JSON和XML渲染 条件请求 数据完整性和并发控制 多个添加操作 数据验证 可扩展的数据验证 资源级缓存控制 版本 验证 CORS跨地资源共享 默认情况下只读 默

  • ESP8266 Apple HomeKit Elgato Eve Motion Sensor ESP8266 based  HomeKit Motion Sensor that works the same as Elgato Eve Motion For Usage please read the Build Instructions Wiki page! This HomeKit enabl

  • 我正在使用webpack来配置源代码映射。我想知道有人能澄清“val”和“evar-source-map”之间的区别吗?我个人看不出有什么区别。

  • 我已经使用Python EVE框架编写了一个API。当试图从AngularJS应用程序访问API时,它显示了如下所示的错误: 有什么问题吗

相关阅读

相关文章

相关问答

相关文档