Skip to main content

Unofficial Lyft Rides API Python SDK

Project description

Python SDK (beta) to support the Lyft Rides API.

Installation

To use the Unofficial Lyft Rides Python SDK:

$ pip install lyft_rides

Head over to pip-installer for instructions on installing pip.

To run from source, you can download the source code for lyft-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 access to resources that are not user-specific (eg. ETA, cost, ride types) you will go through a “2-legged” flow. In this case, you can create a Session using ClientCredentialGrant with the Client ID and Client Secret you received after registering your app.

from lyft_rides.auth import ClientCredentialGrant
from lyft_rides.session import Session

auth_flow = ClientCredentialGrant(client_id=YOUR_CLIENT_ID, client_secret=YOUR_CLIENT_SECRET, scopes=YOUR_PERMISSION_SCOPES)
session = auth_flow.get_session()

Use this Session to create an LyftRidesClient and fetch API resources:

from lyft_rides.client import LyftRidesClient

client = LyftRidesClient(session)
response = client.get_ride_types(37.7833, -122.4167)
ride_types = response.json.get('ride_types')

Authorization

If you need access to a Lyft user’s account in order to make requests on their behalf, you will go through a “3-legged” flow. In this case, you will need the user to grant access to your application through the OAuth 2.0 Authorization Code flow. See Lyft API docs.

The Authorization Code flow is a two-step authorization process. The first step is having the user authorize your app and the second involves requesting an OAuth 2.0 access token from Lyft. This process is mandatory if you want to take actions on behalf of a user or access their information.

from lyft_rides.auth import AuthorizationCodeGrant
auth_flow = AuthorizationCodeGrant(
    YOUR_CLIENT_ID,
    YOUR_CLIENT_SECRET,
    YOUR_PERMISSION_SCOPES,
)
auth_url = auth_flow.get_authorization_url()

Navigate the user to the auth_url where they can grant access to your application. After, they will be redirected to a redirect_url with the format REDIRECT_URL?code=UNIQUE_AUTH_CODE. Use this redirect_url to create a session and start LyftRidesClient.

session = auth_flow.get_session(redirect_url)
client = LyftRidesClient(session)
credentials = session.oauth2credential

Keep credentials information in a secure data store and reuse them to make API calls on behalf of your user. The SDK will handle the token refresh for you automatically when it makes API requests with a LyftRidesClient.

Example Usage

Navigate to the examples folder to access the python scripts examples. Before you can run an example, you must edit the example/config.yaml file and add your app credentials.

To get an LyftRidesClient through the Authorization Code flow, run:

$ python examples/authorization_code_grant.py

The example above stores user credentials in examples/oauth2_session_store.yaml.

Get Available Products

response = client.get_ride_types(37.7833, -122.4167)
ride_types = response.json.get('ride_types')
ride_type = ride_types[0].get('ride_type')

Request a Ride

response = client.request_ride(
    ride_type=ride_type,
    start_latitude=37.77,
    start_longitude=-122.41,
    end_latitude=37.79,
    end_longitude=-122.41,
)
ride_details = response.json
ride_id = ride_details.get('ride_id')

This does not make a real-time request. It makes a request to the sandbox environment.

To send a real-time request to send a Lyft driver to the specified start location, make sure to instantiate your ClientCredentialGrant with

auth_flow = ClientCredentialGrant(client_id=YOUR_CLIENT_ID, client_secret=YOUR_CLIENT_SECRET, scopes=YOUR_PERMISSION_SCOPES, sandbox_mode=False)

or AuthorizationCodeGrant with

auth_flow = AuthorizationCodeGrant(
    YOUR_CLIENT_ID,
    YOUR_CLIENT_SECRET,
    YOUR_PERMISSION_SCOPES,
    sandbox_mode=False
)

The default for sandbox_mode is set to True. See the documentation to read more about using the Sandbox Environment.

Getting help

For full documentation about Lyft Rides API, visit the Lyft Developer Site.

Contributing

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 repository.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lyft_rides-0.1.0b0.zip (29.5 kB view details)

Uploaded Source

Built Distribution

lyft_rides-0.1.0b0-py2.py3-none-any.whl (26.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file lyft_rides-0.1.0b0.zip.

File metadata

  • Download URL: lyft_rides-0.1.0b0.zip
  • Upload date:
  • Size: 29.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for lyft_rides-0.1.0b0.zip
Algorithm Hash digest
SHA256 a671a027969e1b69af978d7fbddad86c4514198d158d97e85836044ea8ee2bb5
MD5 f15ebc1ca6dfcbe093ffd2727e5fe5cc
BLAKE2b-256 9cbb85d62a16c3006054dd60539a4449619af7423a71b00df2b5f1ad68afd22a

See more details on using hashes here.

File details

Details for the file lyft_rides-0.1.0b0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for lyft_rides-0.1.0b0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 db2ca3f079dacbd1e6b962cf512e73e01ae646091f20de235792b302247ed822
MD5 45b17b32e039902728fe7e2076a8b73c
BLAKE2b-256 1c2ed887c3e03e1a3c322b66879f1cb754527102aab98326c943c799126c9417

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page