A Python wrapper for the Safecast API.
Project description
SafecastPy
A pure Python wrapper around the Safecast API.
By the YtoTech members. Checkout our related blog post.
Introduction
This library provides a pure Python interface for the Safecast API.
Safecast provides open hardware and platforms to measure and share data about people environments. Currently the Safecast API allows to publish radiation measurement data.
As they put it:
We believe that having more freely available open data is better for everyone.
Installation
You can install SafecastPy using:
$ pip install SafecastPy
Starting out
First, you'll want to head over to https://api.safecast.org/en-US/users/sign_up and register a new account!
After you register, grab your account API key
from the profile tab.
You can also begin by testing your application on the Safecast API development instance.
First, you'll want to import SafecastPy:
import SafecastPy
Dynamic Function Arguments
Keyword arguments to functions are mapped to the functions available for each endpoint in the Safecast API docs. Doing this allows us to be incredibly flexible in querying the Safecast API, so changes to the API aren't held up from you using them by this library.
Basic Usage
All the method definitions can be found by reading over SafecastPy/endpoints.py.
Initialization
Create a SafecastPy instance with your API key:
import SafecastPy
safecast = SafecastPy.SafecastPy(
api_key='YOUR_API_KEY')
By default it uses the Safecast API production instance. You may want to use the development instance:
import SafecastPy
safecast = SafecastPy.SafecastPy(
api_key='YOUR_API_KEY',
api_url=SafecastPy.DEVELOPMENT_API_URL)
Getting measurements
# Get the 25 last added measurements.
safecast.get_measurements(order='created_at desc'))
# Use paging to navigate through the results.
for i in range(2, 10):
safecast.get_measurements(order='created_at desc', page=i))
# You can also filter by unit.
safecast.get_measurements(unit=SafecastPy.UNIT_CPM)))
# Or date.
safecast.get_measurements(since='2015-09-08', until='2016-12-22')
# And use a combination of all of that.
safecast.get_measurements(
since='2015-09-08', until='2016-12-22',
unit=SafecastPy.UNIT_USV, order='created_at asc',
page=20)
Get more information on the available parameters on the API documentation.
Add a measurement
import datetime, random
measurement = safecast.add_measurement(json={
'latitude': 49.418683,
'longitude': 2.823469,
'value': random.uniform(1, 10),
'unit': SafecastPy.UNIT_CPM,
'captured_at': datetime.datetime.utcnow().isoformat() + '+00:00',
'device_id': 90,
'location_name': '1 Rue du Grand Ferré, Compiègne',
'height': 120
})
print('New measurement id: {0}'.format(measurement['id']))
Retrieve a measurement
safecast.get_measurement(id=52858985)
Upload a bGeigie import
bgeigie_import = safecast.upload_bgeigie_import(files={
'bgeigie_import[source]': open('misc/sample_bgeigie.LOG', 'rb')
}, data={
'bgeigie_import[name]': 'Logging in Compiègne',
'bgeigie_import[description]': 'Around the Université de Technologie',
'bgeigie_import[credits]': 'by YtoTech team',
'bgeigie_import[cities]': 'Compiègne',
'bgeigie_import[orientation]': 'NWE',
'bgeigie_import[height]': '100'
})
print('New import id: {0}'.format(bgeigie_import['id']))
You enjoy the lib? You may check out our blog.
You may also send us love-notes, ask questions or give any comment at yoan@ytotech.com.
Happy hacking!
Contribute
Feel free to open a new ticket or submit a PR to improve the lib.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file SafecastPy-0.1.1.tar.gz
.
File metadata
- Download URL: SafecastPy-0.1.1.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e195931860d637eff12b3c6eb7e0917e38da6d6e764e8934375ca71168358fca |
|
MD5 | 591b136af45c8085b1c7dc987d8cd9c0 |
|
BLAKE2b-256 | 68f48babc6aebfdba8d787dee9061e58d6fc84b2733f8939b7aab939e75a231f |
File details
Details for the file SafecastPy-0.1.1-py2.py3-none-any.whl
.
File metadata
- Download URL: SafecastPy-0.1.1-py2.py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 549b417b348d5122558a25672905ca3f8dc60c07f4fe825d820faeff120a4900 |
|
MD5 | 1430b4f6b3855b5e730d5b914605b7ff |
|
BLAKE2b-256 | e738fb4ef0ae139570781127c0b342bd521316766f1fe34994a3b2bb0906c6d1 |