Skip to main content

smaXtec API client

Project description

# sxapi
smaXtec API Client

Python wrapper for the smaXtec public API

## Usage ##
To use the API smaXtec user credentials (smaXtec Messenger Account) are needed.

```
from sxapi import API

a = API(email="myuser@smaxtec.com", password="mypassword")

# Get organisations
orgas = a.organisations
print orgas

# Get Animals in an organisation
animals = orgas[0].animals
print animals
# Get Sensordata for an animal
data = animals[0].get_frame(["temp", "act"], days_back=10)
print(data)

# Get Events for an animal
events = animals[0].get_events()
print(events.to_series())

# Get by id
print a.get_organisation("5721e3f8a80a5f54c6315131").devices
print a.get_animal("572209c1a80a5f54c631513f").name
print a.get_animal("572209c1a80a5f54c631513f").heats
print a.get_animal("572209c1a80a5f54c631513f").lactations

# Show request stats
a.print_stats()
```

## Low Level Usage ##

```
from sxapi import LowLevelAPI

a = LowLevelAPI(email="user@smaxtec.com", password="mypassword")

# Get by id
print a.get_organisation_by_id("5721e3f8a80a5f54c6315131")
print a.get_animal_by_id("572209c1a80a5f54c631513f")
print a.getAnimal("dsdsd") # from internal
```


## Flask Usage ##
The API Client includes a Flask Extension Module for usage of the LowLevel API.
Usage is only possible with a permanent API Token and an internal endpoint.

```
from flask import Flask, jsonify
from sxapi.ext import FlaskSX

class MYCONFIG(object):
DEBUG = True
TESTING = True
SMAXTEC_API_PUBLIC_ENDPOINT = "http://mypublicapi.smaxtec.com/api/v1"
SMAXTEC_API_PRIVATE_ENDPOINT = "http://127.0.0.1:8787/internapi/v0"
SMAXTEC_API_KEY = "...JWT..."

app = Flask(__name__)
app.config.from_object(MYCONFIG)
api = FlaskSX()
api.init_app(app)

# Example Id: 0700003445
@app.route('/device/<string:device_id>')
def show_device(device_id):
return jsonify(api.get_device_by_id(device_id))

# Example Id: 59f0743b093ed5cab7a1fb18
@app.route('/animal/<string:animal_id>')
def show_animal(animal_id):
return jsonify(api.get_animal_by_id(animal_id))

@app.route('/')
def show_home():
public = api.get_public_status()
private = api.get_private_status()
return jsonify({"public": public, "private": private})

if __name__ == "__main__":
app.run()
```

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

sxapi-0.9.tar.gz (12.0 kB view hashes)

Uploaded Source

Built Distributions

sxapi-0.9-py3-none-any.whl (15.5 kB view hashes)

Uploaded Python 3

sxapi-0.9-py2-none-any.whl (15.4 kB view hashes)

Uploaded Python 2

Supported by

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