简体   繁体   English

如何在python中使用API​​查询MySQL数据库?

[英]How to query MySQL database using API in python?

I have my data in database, and I want to build an API using python to query the database. 我的数据库中有数据,我想使用python构建一个API来查询数据库。 What do I use or where do I even start ? 我使用什么,甚至从哪里开始?

I can connect to my database and pull the data. 我可以连接到数据库并提取数据。 But I do not know how to build an API for other users to query the database 但是我不知道如何为其他用户建立一个API来查询数据库

NOT a trivial solution, but worth looking into, depending on how big a project this is and what else you may want to do with Python and MySQL. 这不是一个简单的解决方案,但是值得研究,这取决于项目的规模以及您可能还想对Python和MySQL做些什么。

Django is a framework for Python that can handle a lot of things but, most importantly, provides a very powerful interface to MySQL and other databases. Django是Python的框架,可以处理很多事情,但最重要的是,它提供了一个非常强大的MySQL和其他数据库接口。

One of the many add-ons for Django is Django REST Framework which is specifically designed for setting up Restful APIs using Django & Python. Django的众多附加组件之一是Django REST Framework ,它专门设计用于使用Django&Python设置Restful API。

I have used Django & Django REST Framework extensively. 我已经广泛使用了Django和Django REST Framework。 It can take a while to get up to speed, but I think still a lot less work than if you were to take a basic connector between Python & MySQL (having to code SQL statements manually) and code the API interface at a lower level (Django REST Framework isn't perfect but it takes care of a lot of the details). 加快速度可能需要一段时间,但是与在Python和MySQL之间建立基本连接器(必须手动编码SQL语句)并在较低级别编码API接口相比,我认为工作量要少得多。 Django REST Framework并不是完美的,但它照顾了很多细节。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM