Skip to main content

Onfleet Python Wrapper

Build License Latest version Top language Downloads

Read this document in another language:
正體中文
Español

Visit our blog post on the API wrapper project to learn more about our initiatives.
If you have any questions, please reach us by submitting an issue here or contact support@onfleet.com.

Table of contents

Synopsis

The Onfleet Python library provides convenient access to the Onfleet API.

Installation

pip install pyonfleet

Usage

Before using the API wrapper, you will need to obtain an API key from one of your organization's admins.

Creation and integration of API keys are performed through the Onfleet dashboard.

To authenticate, you will also need to create a file named .auth.json under your working directory –this is where you will store your API credentials.

The format of .auth.json is shown below:

{
    "API_KEY": "<your_api_key>"
}

You can also opt in to not store your API key here and pass it as param to Onfleet:

from onfleet import Onfleet

# Option 1 - Recommended
onfleet_api = Onfleet()  # Using the .auth.json file

# Option 2
onfleet_api = Onfleet(api_key="<your_api_key>")  # Without the .auth.json file

Another optional parameter for Onfleet is custom_headers where you can pass in headers to be applied to all requests. For example:

onfleet_api = Onfleet(custom_headers={"<header_name>": "<header_value>"})

Once the Onfleet object is created, you will get access to all the API endpoints as documented in the Onfleet API documentation.

Unit testing using Docker

docker-compose up --build

Throttling

Rate limiting is enforced by the API with a threshold of 20 requests per second across all your organization's API keys. Learn more about it here.

Responses

Responses of this library are instances of Response from the requests library.

Supported CRUD operations

Here are the operations available for each entity:

Entity GET POST PUT DELETE
Admins/Administrators get() create(body={})
matchMetadata(body={})
update(id, body={}) deleteOne(id)
Containers get(workers=id)
get(teams=id)
get(organizations=id)
x update(id, body={}) x
Destinations get(id) create(body={})
matchMetadata(body={})
x x
Hubs get() create(body={}) update(id, body={}) x
Organization get()
get(id)
x insertTask(id, body={}) x
Recipients get(id)
get(name="")
get(phone="")
create(body={})
matchMetadata(body={})
update(id, body={}) x
Route Plans get(id)
get(queryParams="")
create(body={}) update(id, body={})
addTasksToRoutePlan(id, body={})
deleteOne(id)
Tasks get(queryParams={})
get(id)
get(shortId=id)
create(body={})
clone(id)
forceComplete(id)
batchCreate(body={})
batchCreateAsync(body={})
getBatchCreateAsyncStatus(id)
autoAssign(body={})
matchMetadata(body={})
update(id, body={}) deleteOne(id)
Teams get()
get(id)
getWorkerEta(id, queryParams={})
getTasks(id, queryParams={})
create(body={})
autoDispatch(id, body={})
update(id, body={})
insertTask(id, body={})
deleteOne(id)
Webhooks get() create(body={}) x deleteOne(id)
Workers get()
get(id)
get(queryParams={})
getByLocation(queryParams={})
getSchedule(id)
getTasks(id, queryParams={})
create(body={})
setSchedule(id, body={})
matchMetadata(body={})
getDeliveryManifest(workerId, hubId, googleApiKey, queryParams={})
update(id, body={})
insertTask(id, body={})
deleteOne(id)

GET Requests

To get all the documents within an endpoint:

get()
Examples of get()
onfleet_api.workers.get()
onfleet_api.workers.get(queryParams="")

Optionally you can use queryParams for some certain endpoints.
Refer back to API documentation for endpoints that support query parameters.

# Option 1
onfleet_api.workers.get(queryParams={"phones": "<phone_number>"})

# Option 2
onfleet_api.workers.get(queryParams="phones=<phone_number>")

To get one of the document within an endpoint, specify the param that you wish to search by:

get(param="<value>")
Examples of get(param)
onfleet_api.workers.get(id="<24_digit_ID>")
onfleet_api.workers.get(id="<24_digit_ID>", queryParams={"analytics": "true"})

onfleet_api.tasks.get(shortId="<shortId>")

onfleet_api.recipients.get(phone="<phone_number>")
onfleet_api.recipients.get(name="<name>")

onfleet_api.containers.get(workers="<worker_ID>")
onfleet_api.containers.get(teams="<team_ID>")
onfleet_api.containers.get(organizations="<organization_ID>")

Note: don't use Python-style True and False for boolean values - supply these as strings like "true" or "false".

To get a driver by location, use the getByLocation function:

getByLocation(queryParams="<location_params>")
Examples of getByLocation
location_params = {
    "longitude": "-122.4",
    "latitude": "37.7601983",
    "radius": "6000",
}

onfleet_api.workers.getByLocation(queryParams=location_params)

POST Requests

To create a document within an endpoint:

create(body="<data>")
Examples of create()
data = {
    "name": "John Driver",
    "phone": "+16173428853",
    "teams": ["<team_ID>", "<team_ID> (optional)", "..."],
    "vehicle": {
        "type": "CAR",
        "description": "Tesla Model S",
        "licensePlate": "FKNS9A",
        "color": "purple",
    },
}

onfleet_api.workers.create(body=data)

Extended POST requests include clone, forceComplete, batchCreate, autoAssign on the Tasks endpoint; setSchedule on the Workers endpoint; autoDispatch on the Teams endpoint; and matchMetadata on all supported entities. For instance:

onfleet_api.tasks.clone(id="<24_digit_ID>")
onfleet_api.tasks.forceComplete(id="<24_digit_ID>", body="<data>")
onfleet_api.tasks.batchCreate(body="<data>")
onfleet_api.tasks.autoAssign(body="<data>")

onfleet_api.workers.setSchedule(id="<24_digit_ID>", body="<data>")
onfleet.api.workers.getDeliveryManifest(workerId="<workerId>", hubId="<hubId>", googleApiKey="<googleApiKey>", queryParams={"<startDate>", "<endDate>"})

onfleet_api.teams.autoDispatch(id="<24_digit_ID>", body="<data>")

onfleet_api.<entity_name_pluralized>.matchMetadata(body="<data>")

For more details, check our documentation on clone, forceComplete, batchCreate, autoAssign, setSchedule, matchMetadata, getDeliveryManifest and autoDispatch.

PUT Requests

To update a document within an endpoint:

update(id="<24_digit_ID>", body="<data>")
Examples of update()
new_data = {
    "name": "Jack Driver",
}

onfleet_api.workers.update(id="<24_digit_ID>", body=new_data)
Examples of insertTask()
onfleet_api.workers.insertTask(id="<24_digit_ID>", body="<data>")

DELETE Requests

To delete a document within an endpoint:

deleteOne(id="<24_digit_ID>")
Examples of deleteOne()
onfleet_api.workers.deleteOne(id="<24_digit_ID>")

Go to top.

Metadata

Release files for pyonfleet 1.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyonfleet 1.6.0
File Size Uploaded
pyonfleet-1.6.0.tar.gz 16.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyonfleet 1.6.0
File Interpreter ABI Platform
pyonfleet-1.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 26.8 kB

Release files / pyonfleet-1.6.0.tar.gz

Download URL pyonfleet-1.6.0.tar.gz
Size 16.8 kB
Tags Source
SHA-256 checksum
How to use checksums
34817cd4c0a459a08e585fb125c96e66a7ce7b4396d710ab61952e05c4e9d535
BLAKE2b-256 checksum
How to use checksums
cd39823252ea86c7410eb624e2d7ae1f290cf5f1dc36faa367a659bc37fbf0d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.24

Release files / pyonfleet-1.6.0-py3-none-any.whl

Download URL pyonfleet-1.6.0-py3-none-any.whl
Size 10.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6e9aaf8d42f755636ee24f4f7f24867d35cdf0f60507a5b9b7fb7527178f3f60
BLAKE2b-256 checksum
How to use checksums
a7dc79c77d8cbe9ecca89169f5005447d7475716ee140bfa0e6b63b460ee4ca8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.24

Release history Release notifications | RSS feed

This release

1.6.0 This release

2 release files

1.5.0

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.1

2 release files

1.2

2 release files

1.1.6

2 release files

1.1.5

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page