This repo hosts a beta version of the Samsara SDKs.
Currently there is only one SDK: python-sdk
.
This SDK was generated off of Samsara's Open API Spec: swagger.json
.
It was generated using the OpenAPI Generator.
The python-sdk
directory contains the direct output of the generator, including automatically generated documentation.
The automatically generated documentation can be a little confusing, and we have plans to improve that. For now, here's some getting started information:
The SDK should work with either Python 2 or Python 3.
- Clone or download this project.
- Open a command prompt or terminal.
cd
intosamsara-sdks/python-sdk
.- Run
python setup.py install
.
You should now be able to import the SDK into your python program. The name of the module is samsara
:
import samsara
You can run the Python interpreter by running:
python
from the command prompt. From there, you can import the samsara module.
You must run the setup.py
file from the python-sdk
folder. This is because this folder contains the list of dependencies required by the SDK.
If you see and error like [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/
while trying to run the setup script, you may be trying to install with the default macOS system Python 2 version. You can either follow the instructions below for installing with Python 2 or upgrade to Python 3.
-
Install pip. It says that pip is already installed if you are using Python 2.7.9, but macOS actually doesn't install pip by default, so go ahead and continue with the installation instructions you find there.
-
Add pip to your
$PATH
variable by running:
echo 'export PATH="/Users/$(whoami)/Library/Python/2.7/bin:$PATH"' >> ~/.bash_profile
-
Run
pip install --upgrade setuptools
-
Make sure you are in the
samsara-sdks/python-sdk
directory and run:python setup.py install --user
-
Install Homebrew.
-
Run
brew install python3
. Note: To run Python 3 you must runpython3
instead ofpython
. -
Make sure you are in the
samsara-sdks/python-sdk
directory and run:python3 setup.py install
.
Note: this may be subject to change as we improve the SDK.
import samsara
# Create an ApiClient with an API access `token`. You can provide your access token to the variable `token` below.
client = samsara.ApiClient(header_name='Authorization', header_value='Bearer {token}'.format(token=token))
# Create an instance of the Addresses Api
api = samsara.DefaultApi(api_client=client)
# Instantiate an AddressCreate object to send to the Samsara API
new_address = samsara.CreateAddressRequest(
name="SF6",
formatted_address="350 Rhode Island St, San Francisco, CA",
geofence=samsara.AddressGeofence(
circle=samsara.AddressGeofenceCircle(
radius_meters=25
)
)
)
# Call `create_address` with the CreateAddressRequest object
response = api.create_address(address=new_address)
# Access the id of the newly created address
new_address_id = response.data.id
You can see more examples in the examples
folder.
To run the examples, you must provide an API access token:
python examples/vehicle_locations/get_vehicle_locations.py YOUR_ACCESS_TOKEN