sxapi_legacy
smaXtec API Client
⚠️ The API of this package is deprecated and will be changed with version 1.x ⚠️
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
print a.get_animal("572209c1a80a5f54c631513f").current_dim
print a.get_animal("572209c1a80a5f54c631513f").dim_range(datetime.datetime(2018,1,1), datetime.datetime.now(), interval=12*60*60)
# Show request stats
a.print_stats()
Timezone Awareness
By default the API Client tries to make all datetimes timezone aware with pendulum datetime instances. See: https://pendulum.eustace.io/docs/
To deactivate this behaviour create API Clients with tz_aware=False
from sxapi import API
a = API(email="myuser@smaxtec.com", password="mypassword", tz_aware=False)
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 works only with api key
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()
Development
To build a new pip version increase version and tag with git tag -a "vX.X". Build artifacts and push to pip
python setup.py sdist bdist_wheel
twine upload dist/*
Metadata
Release files for sxapi 0.15
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| sxapi-0.15.tar.gz | 18.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sxapi-0.15-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 37.6 kB
Release files / sxapi-0.15.tar.gz
| Download URL | sxapi-0.15.tar.gz |
|---|---|
| Size | 18.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
380af1da29e53f1c7c28173b1a53344840f4595f1710f246a832b867cd6e949a
|
|
BLAKE2b-256 checksum How to use checksums |
532b56607558bab44b54947bb211fc22c1f2ed14ae17b61d8fa1ebe28ba2b5fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.6
|
Release files / sxapi-0.15-py3-none-any.whl
| Download URL | sxapi-0.15-py3-none-any.whl |
|---|---|
| Size | 19.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
41ddc922bb2dcd2431a5999ad6651e2221939a5d152f409ac109d7435a889a66
|
|
BLAKE2b-256 checksum How to use checksums |
f87c986a992ffd1386724ab7375620e695f017783880f51c5ed398988f6c2d81
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.6
|
Security for sxapi 0.15
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.