L
L
louvremaster2015-04-14 16:48:51
linux
louvremaster, 2015-04-14 16:48:51

How to write proper API under python?

Hello!
Please share your experience. Purpose: to write an API (the purpose of the API itself is not important in this case, just input / output of certain data) under python, the main task is to access the API in two ways, via the web, for example:
api.host/?func=create&user=test
and via console:
[[email protected] ~]# /usr/local/api/bin/api.py func=create user=test
Perhaps there are ready-made schemes or frameworks?
Thank you.

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
H
Hu New, 2015-04-14
@stopbreath

Maybe this will help you. List of blogs on writing api. Even in python there are as many as 4 examples

R
Roman, 2015-04-15
@skipirich

As mentioned above, the API can be written on any framework, the main thing is that it should comply with the REST methodology (for good). Alternatively, you can take a look at this blog.miguelgrinberg.com/post/designing-a-restful-a... post here showing how to build an api using flask as an example. The post does not cover the use of flask.ext.restful well, I advise you to take a look at it if you decide to do it with flask.
And here's one more note - restapi implies working through an http server, so [[email protected] ~]# /usr/local/api/bin/api.py func=create user=test will not work from the console. Should be something like
[[email protected] ~]# curl -i api.host/?func=create&user=test

M
Max, 2015-04-14
@AloneCoder

Check out Fhalcon

L
louvremaster, 2015-04-14
@louvremaster

I used to use bottle exclusively for the web for the API, as far as I understand, all these frameworks like fhalcon and bottle do not allow you to use the console version at the same time, so you may need to write some kind of wrapper separately for the console, and already take these into account in your libraries all arguments. But I feel that this is a crutch :)
By the way, does anyone have experience with libvirt-python? I did not find in the documentation how to change the domain config like virsh edit, is it really "hands" of the xml itself in /etc/libvirt/qemu/domain.xml?

V
Vadim Shandrinov, 2015-04-14
@suguby

I would use habrahabr.ru/post/160117 in Django to implement the command line api through manage commands - there is a wrapper for calls :)

V
Vladimir Abiduev, 2015-04-14
@gunlinux

www.youtube.com/watch?v=px_vg9Far1Y
http://blog.futurecolors.ru/2012/07/developing-res...
Flask for the web
Proper api implies restfull

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question