通过HTTP请求访问python函数。

spineapi的Python项目详细描述


脊椎API

通过HTTP请求访问python函数。在

它简单、干净、使用方便。它也适用于jupyter笔记本电脑。在

1。设置api服务器

{str}1前提条件

  1. 确保可以通过端口3000访问服务器
  2. 有节点.js安装在服务器上

安装

$ git clone https://github.com/spineapi/spine-api
$ cd spine-api/server
$ npm install

Run server

^{pr2}$

现在您可以通过http://YOUR_服务器_IP:3000。复制密码。在

安装

$ pip instal spineapi

将python脚本连接到服务器

1。导入库

fromspineapiimportConnection

2。定义您的功能

defhello_function(input):# ...# do something# ...returnoutput

3。指定namedescription初始化项目

spine_connection=Connection(project_path="hello_project",project_name="My first project",description="Arithmetic operations",base_url="http://localhost:3000",passcode="xxxx-xxxx-xxxx-xxxxx",author="",# Optionallink=""# Optional)

4。注册您的功能

spine_connection.register_function(pathname='hello_function',function=hello_function,# ============ Optional ==================# Set True if you want to protect this APIrequiresAuth=False,authToken="xxx",# ========================================)

可以通过/api/hello_project/hello_function访问该函数

^{str 1}5美元。运行

spine_connection.run()

就这样!现在可以通过httppost请求与ML模型通信。在

6。发送请求

Note您必须首先对请求数据运行JSON.stringify(input)。在

constdata={input:JSON.stringify(YOUR_INPUT)// ============ Optional ==================// Required if the API is protectedauthToken:"xxx",// ========================================}

将请求正文发布到终结点。在

consturl='http://localhost:3000/api/hello_project/hello_function';fetch(url,{method:'POST',body:JSON.stringify(data),headers:newHeaders({'Content-Type':'application/json'})}).then(res=>res.json()).catch(error=>console.error('Error:',error)).then(response=>console.log('Success:',response));

许可证

MIT

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
jframe为什么JAVA paint()方法不起作用?   java Guice:将ContainerRequestContext注入拦截器   java如何优雅地关闭Spring JMS MessageListenerAdapter   java如何在Spring中设置快照隔离级别   Java中的安卓平台独立信任存储路径   java无法在eclipse中运行hello world程序   java Sinch空指针问题   使用Java将JSON流式传输到BigQuery   java从“大数据”中选择什么Swing控件?   java通过对象字段过滤/排序集合?   java将数据从活动传递到另一个活动中的片段   java访问打包在jar文件中的文档   Java获取事件的大小。getDragboard()。getFiles()。流()。映射(文件::长度)。toString());   java Android libgdx:启动程序图标按下后,启动屏幕不会立即显示   java如何在Google App Engine灵活环境中配置oracle jdk   java有没有办法减少这些行?   Java:客户端socket不读取第二行,在终止符行之后保持打开状态   java以编程方式获取api 29上的所有APK文件   java ActionBar按钮不显示