Skip to main content

Access your python functions through HTTP requests.

Project description

Spine API

Access your python functions through HTTP requests.

It is simple, clean, and easy to use. It works with jupyter notebooks too.

1. Setup your api server

Prerequisites

  1. Make sure your server is accessible through port 3000
  2. Have Node.js installed on your server

Installation

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

Run server

$ node server.js

Now you can access your server through http://YOUR_SERVER_IP:3000. Copy the passcode.

Installation

$ pip instal spineapi

Connect your python script to the server

1. Import the library

from spineapi import Connection

2. Define your function

def hello_function (input):
  # ...
  # do something
  # ...
  return output

3. Specify name and description to initialize your project

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="", # Optional
  link="" # Optional
)

4. Register your function(s)

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

The function will be accessible through /api/hello_project/hello_function

5. Run

spine_connection.run()

That's it! You can now communicate with your ML model through HTTP post requests.

6. Send requests

Note You have to first run JSON.stringify(input) for the request data.

const data = {
  input: JSON.stringify(YOUR_INPUT)
  // ============ Optional ==================
  // Required if the API is protected
  authToken: "xxx",
  // ========================================
}

Post request body to the endpoint.

const url = 'http://localhost:3000/api/hello_project/hello_function';

fetch(
  url,
  {
    method: 'POST',
    body: JSON.stringify(data),
    headers: new Headers({ 'Content-Type': 'application/json' })
  }
)
.then(res => res.json())
.catch(error => console.error('Error:', error))
.then(response => console.log('Success:', response));

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spineapi-0.1.0.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spineapi-0.1.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file spineapi-0.1.0.tar.gz.

File metadata

  • Download URL: spineapi-0.1.0.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.4

File hashes

Hashes for spineapi-0.1.0.tar.gz
Algorithm Hash digest
SHA256 55e6113908f4c772a09a692b52f46a8fbf8962689d25cc5c4d834ea7179d9ec9
MD5 c68d85b3b11a79558f4441de4a06c086
BLAKE2b-256 00aa91a59d21f73d6be8774f436c232b6902e977210960340ed2f9af702cebb3

See more details on using hashes here.

File details

Details for the file spineapi-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: spineapi-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.4

File hashes

Hashes for spineapi-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 287f961e1d7f94ee486a077d2fde031516bce37f15db1005df2c484507d2f107
MD5 77ba5e506b835edbd9750c0196c522a5
BLAKE2b-256 50f11db161d918c4c326dd895b928489481e786e2d9539cc2ec29440d47b20c1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page