Official Uber API Python SDK
Project description
Python SDK (beta) to support the Uber Rides API.
Installation
To use the Uber Rides Python SDK:
$ pip install uber_rides
Head over to pip-installer for instructions on installing pip.
To run from source, you can download the source code for uber-rides, and then run:
$ python setup.py install
We recommend using virtualenv when setting up your project environment. You may need to run the above commands with sudo if you’re not using it.
Read-Only Use
If you just need read-only access to Uber API resources, like getting a location’s available products, create a Session with the server token you received after registering your app.
from uber_rides.session import Session
session = Session(server_token=YOUR_SERVER_TOKEN)
Use this Session to create an UberRidesClient and fetch API resources:
from uber_rides.client import UberRidesClient
client = UberRidesClient(session)
response = client.get_products(37.77, -122.41)
products = response.json.get('products')
Example Apps
Navigate to the example folder to access the python example apps. Before you can run an example, you must edit the example/config.*.yaml file and add your app credentials from the Uber developer dashboard.
To get an UberRidesClient through the Authorization Code flow, run:
$ python example/authorize_rider.py
The example above stores user credentials in example/oauth2_rider_session_store.yaml. To create an UberRidesClient with these credentials and go through a surge ride request run:
$ python example/request_ride.py
—
To get an UberRidesClient authorized for driver endpoints, run:
$ python example/authorize_driver.py
The example above stores user credentials in example/oauth2_driver_session_store.yaml.
Flask Demo Apps
To get an understanding of how the sdk can be use in an example app see the flask examples for rider and driver dashboards:
$ pip install flask
$ python example/rider_dashboard.py
$ python example/driver_dashboard.py
Get Available Products
response = client.get_products(37.77, -122.41)
products = response.json.get('products')
product_id = products[0].get('product_id')
Get Price Estimates
response = client.get_price_estimates(
start_latitude=37.770,
start_longitude=-122.411,
end_latitude=37.791,
end_longitude=-122.405,
seat_count=2
)
estimate = response.json.get('prices')
Get Rider Profile
response = client.get_rider_profile()
profile = response.json
first_name = profile.get('first_name')
last_name = profile.get('last_name')
email = profile.get('email')
Get User History
response = client.get_user_activity()
history = response.json
Request a Ride
# Get products for location
response = client.get_products(37.77, -122.41)
products = response.json.get('products')
product_id = products[0].get('product_id')
# Get upfront fare for product with start/end location
estimate = client.estimate_ride(
product_id=product_id,
start_latitude=37.77,
start_longitude=-122.41,
end_latitude=37.79,
end_longitude=-122.41,
seat_count=2
)
fare = estimate.json.get('fare')
# Request ride with upfront fare for product with start/end location
response = client.request_ride(
product_id=product_id,
start_latitude=37.77,
start_longitude=-122.41,
end_latitude=37.79,
end_longitude=-122.41,
seat_count=2,
fare_id=fare['fare_id']
)
request = response.json
request_id = request.get('request_id')
# Request ride details from request_id
response = client.get_ride_details(request_id)
ride = response.json
# Cancel a ride
response = client.cancel_ride(request_id)
ride = response.json
This makes a real-world request and send an Uber driver to the specified start location.
To develop and test against request endpoints in a sandbox environment, make sure to instantiate your UberRidesClient with
client = UberRidesClient(session, sandbox_mode=True)
The default for sandbox_mode is set to False. See our documentation to read more about using the Sandbox Environment.
Update Sandbox Ride
If you are requesting sandbox rides, you will need to step through the different states of a ride.
response = client.update_sandbox_ride(ride_id, 'accepted')
response = client.update_sandbox_ride(ride_id, 'in_progress')
If the update is successful, response.status_code will be 204.
The update_sandbox_ride method is not valid in normal mode, where the ride status will change automatically.
Get Driver Profile
response = client.get_driver_profile()
profile = response.json
first_name = profile.get('first_name')
last_name = profile.get('last_name')
email = profile.get('email')
Get Driver Trips
response = client.get_driver_trips()
trips = response.json
Get Driver Payments
response = client.get_driver_payments()
payments = response.json
Get Uber for Business Receipts
from uber_rides.auth import ClientCredentialGrant
from uber_rides.client import UberRidesClient
auth_flow = ClientCredentialGrant(
<CLIENT_ID>,
<SCOPES>,
<CLIENT_SECRET>
)
session = auth_flow.get_session()
client = UberRidesClient(session)
receipt = client.get_business_trip_receipt('2a2f3da4-asdad-ds-12313asd')
pdf_url = client.get_business_trip_receipt_pdf_url('2a2f3da4-asdad-ds-12313asd')
Getting help
Uber developers actively monitor the Uber Tag on StackOverflow. If you need help installing or using the library, you can ask a question there. Make sure to tag your question with uber-api and python!
For full documentation about our API, visit our Developer Site.
See the Getting Started Tutorial.
Contributing
We love contributions. If you’ve found a bug in the library or would like new features added, go ahead and open issues or pull requests against this repo. Write a test to show your bug was fixed or the feature works as expected.
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 uber_rides-0.6.0.tar.gz
.
File metadata
- Download URL: uber_rides-0.6.0.tar.gz
- Upload date:
- Size: 103.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | adca8a529e631efed61f6d59753d09f58cdd274ef66d1ebeb514a1afc9299b60 |
|
MD5 | 509edf2835ce8c922ed5a6f2f5946132 |
|
BLAKE2b-256 | 70731d8751d32da910cfb751e7e33fe6dba062560e8fa6467aea43abdee2ae56 |
File details
Details for the file uber_rides-0.6.0-py2.py3-none-any.whl
.
File metadata
- Download URL: uber_rides-0.6.0-py2.py3-none-any.whl
- Upload date:
- Size: 57.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf41aa8c521e0581dd4de810235811fe76c315c05723f64796580dead068aa4f |
|
MD5 | fde2aa07f914fc282b4b84ce3d405062 |
|
BLAKE2b-256 | 26a7a7263ab7a8dfe6c0aa435ca86623f6215fcfbf17082dd95c92e22a3b959a |