如何为Python应用程序编写API? [英] How to write an API for a Python application?

查看:63
本文介绍了如何为Python应用程序编写API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好

我想为一段Python代码创建一个API。 API由非Python代码使用



它应该支持双向交互,两者都访问API上的函数和b $ b API能够在其客户端上引发事件。

最好的方法是什么?

我虽然把它作为python COM服务器但是我不是熟悉COM

我看到在python中实现一个带有事件的COM服务器对我来说不是很简单。

有没有更好的(或更简单的解决方案?

这样做的常用方法有哪些?


任何答案都将受到高度赞赏。

问候

Gary

Hello
I would like to create an API for a piece of Python code. The API is for use
by non Python code.
It should support interaction in both directions, both accessing functions
on the API and the ability for the API to raise events on its client.
What is the best way to do that?
I though of doing it as a python COM server but I am not familiar with COM
and I saw that implementing a COM server with events in python is not
trivial for me.
Is there a better (or simpler) solution?
What are the common ways for doing that?

Any answer would be highly appreciated.
Regards
Gary

推荐答案

虽然不确定你想要实现的行为,但是XML-RPC来了
想想
。但它基于HTTP协议,客户端将

请求发送给必须响应的服务器。服务器无法启动

交互。

XML-RPC广泛可用,并且非常易于实现。


注意:为了让服务器在客户端引发事件,客户端只需要定期提出*需要任何来自我的*类型的请求

允许服务器返回其请求以响应

客户端。当然这个解决方案会使多余的调用占用一些带宽,因此可能并不适用于所有情况。

While not sure of the behavior you are trying to achieve, XML-RPC comes
to mind. But it''s based on HTTP protocol in which the client puts
request to the server which has to respond. The server cannot initiate
interactions.
XML-RPC is both widely avalaible, and very easy to implement.

NOTE: in order for the server to raise events in the client, the client
needs only raise periodically a *need-anything-from-me* type of request
which permits the server to return its request in response to the
client. Naturally this solution makes superfluous calls takes some
bandwidth, so it might not be appropriate in every circumstance.


虽然不确定你想要实现的行为,XML-RPC想到了。
。但它基于HTTP协议,客户端将

请求发送给必须响应的服务器。服务器无法启动

交互。

XML-RPC广泛可用,并且非常易于实现。


注意:为了让服务器在客户端引发事件,客户端只需要定期提出*需要任何来自我的*类型的请求

允许服务器返回其请求以响应

客户端。当然这个解决方案会使多余的调用占用一些带宽,因此可能并不适用于所有情况。

While not sure of the behavior you are trying to achieve, XML-RPC comes
to mind. But it''s based on HTTP protocol in which the client puts
request to the server which has to respond. The server cannot initiate
interactions.
XML-RPC is both widely avalaible, and very easy to implement.

NOTE: in order for the server to raise events in the client, the client
needs only raise periodically a *need-anything-from-me* type of request
which permits the server to return its request in response to the
client. Naturally this solution makes superfluous calls takes some
bandwidth, so it might not be appropriate in every circumstance.


谢谢

这是一个有趣的解决方案,但我需要一个更紧密耦合的解决方案,

与实时事件,所以沟通真的必须是两种方式,而不是

by polling。

感谢您抽出时间。

Gary

< jm ********* @ gmail.com>在消息中写道

news:11 ********************** @ o13g2000cwo.googlegr oups.com ...
Thanks
Its an interesting solution but I need a more closely coupled solution,
with real time events, so the communication really has to be 2 ways, and not
by polling.
Thanks for putting the time and though.
Gary
<jm*********@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
虽然不确定您想要实现的行为,但请记住XML-RPC。但它基于HTTP协议,客户端将请求发送给必须响应的服务器。服务器无法启动
交互。
XML-RPC既广泛可用,又易于实现。

注意:为了让服​​务器在客户端引发事件,客户端只需要定期提出*需要任何来自我的*类型的请求
,它允许服务器返回其请求以响应客户端。当然,这种解决方案会使多余的调用占用一些带宽,因此可能并不适用于所有情况。
While not sure of the behavior you are trying to achieve, XML-RPC comes
to mind. But it''s based on HTTP protocol in which the client puts
request to the server which has to respond. The server cannot initiate
interactions.
XML-RPC is both widely avalaible, and very easy to implement.

NOTE: in order for the server to raise events in the client, the client
needs only raise periodically a *need-anything-from-me* type of request
which permits the server to return its request in response to the
client. Naturally this solution makes superfluous calls takes some
bandwidth, so it might not be appropriate in every circumstance.



这篇关于如何为Python应用程序编写API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆