Package: lyft_rides
Python SDK (beta) to support theLyft Rides API.InstallationTo use the Unofficial Lyft Rides Python SDK:$pipinstalllyft_ridesHead over topip-installerfor instructions on installing pip.To run from source, you candownload the source codefor lyft-rides, and then run:$pythonsetup.pyinstallWe recommend usingvirtualenvwhen setting up your project environment. You may need to run the above commands withsudoif you’re not using it.Read-Only UseIf 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 afterregistering your app.fromlyft_rides.authimportClientCredentialGrantfromlyft_rides.sessionimportSessionauth_flow=ClientCredentialGrant(YOUR_CLIENT_ID,YOUR_CLIENT_SECRET,YOUR_PERMISSION_SCOPES,)session=auth_flow.get_session()Use this Session to create an LyftRidesClient and fetch API resources:fromlyft_rides.clientimportLyftRidesClientclient=LyftRidesClient(session)response=client.get_ride_types(37.7833,-122.4167)ride_types=response.json.get('ride_types')AuthorizationIf 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. SeeLyft 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.fromlyft_rides.authimportAuthorizationCodeGrantauth_flow=AuthorizationCodeGrant(YOUR_CLIENT_ID,YOUR_CLIENT_SECRET,YOUR_PERMISSION_SCOPES,)auth_url=auth_flow.get_authorization_url()Navigate the user to theauth_urlwhere they can grant access to your application. After, they will be redirected to aredirect_urlwith the format REDIRECT_URL?code=UNIQUE_AUTH_CODE. Use thisredirect_urlto create a session and start LyftRidesClient.session=auth_flow.get_session(redirect_url)client=LyftRidesClient(session)credentials=session.oauth2credentialKeepcredentialsinformation 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 UsageNavigate to theexamplesfolder to access the python scripts examples.  Before you can run an example, you must edit theexample/config.yamlfile and add your app credentials.To get an LyftRidesClient through the Authorization Code flow, run:$pythonexamples/authorization_code_grant.pyThe example above stores user credentials inexamples/oauth2_session_store.yaml.Get Available Productsresponse=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 Rideresponse=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.jsonride_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 withauth_flow=ClientCredentialGrant(YOUR_CLIENT_ID,YOUR_CLIENT_SECRET,YOUR_PERMISSION_SCOPES,sandbox_mode=False)or AuthorizationCodeGrant withauth_flow=AuthorizationCodeGrant(YOUR_CLIENT_ID,YOUR_CLIENT_SECRET,YOUR_PERMISSION_SCOPES,sandbox_mode=False,)The default forsandbox_modeis set toTrue. See thedocumentationto read more about using the Sandbox Environment.Getting helpFor full documentation about Lyft Rides API, visit theLyft Developer Site.ContributingIf 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.