Client for the Alert management API
General users can use the API client to request available data within their respective scope (i.e. as a private individual, you won't have access to the data from devices of firefighters; however you will have access to all the data related to your devices). You can find several examples below:
API_URL = os.getenv("API_URL", "http://localhost:5050/api/v1/")
login = os.getenv("USER_LOGIN", "superadmin_login")
pwd = os.getenv("USER_PWD", "superadmin_pwd")
token = requests.post(
urljoin(API_URL, "login/creds"),
data={"username": login, "password": pwd},
timeout=5,
).json()["access_token"]
api_client = Client(token, "http://localhost:5050", timeout=10)
# List organizations accessible in your scope
organizations = api_client.fetch_organizations()
# Get the url of the image of a detection
url = api_client.get_detection_url(detection_id)
cam_token = requests.post(urljoin(API_URL, f"cameras/{cam_id}/token"), headers=admin_headers, timeout=5).json()[
"access_token"
]
camera_client = Client(cam_token, "http://localhost:5050", timeout=10)
response = cam_client.create_detection(image, 123.2)
Python 3.8 (or higher) and pip/conda are required to install the client of the alert API.
You can install the last stable release of the package using pypi as follows:
pip install pyroclient
or using conda:
conda install -c pyronear pyroclient
Alternatively, if you wish to use the latest features of the project that haven't made their way to a release yet, you can install the package from source (install Git first):
git clone https://github.com/pyronear/pyro-api.git
$pip install -e pyro-api/client/.
What you need to use the client:
- URL to the target Alert API
- credentials (login & password)
If you're running your local/own instance of the API, you can generate your own credentials. Otherwise, you will need to request credentials from the instance administrator. For our public API instance, at the moment, we don't provide public access to the API, it's only reserved to these type of users:
- Pyronear members
- firefighters and stakeholders of wildfire prevention
- People looking at registering their own device
The full package documentation is available here for detailed specifications.
Any sort of contribution is greatly appreciated!
You can find a short guide in CONTRIBUTING
to help grow this project!
Distributed under the Apache 2.0 License. See LICENSE
for more information.