Skip to main content

A Python wrapper for the Clef API

Project description

python-clef
===========

A Python wrapper for the `Clef <https://getclef.com/>`__ API.
Authenticate a user and access their information in two lines of code.

Requires
--------

- requests

Installation
------------

| Install using pip:
| ``pip install clef``

Getting Started
---------------

The Clef API uses OAuth2 for authentication. Pass your credentials to
the ClefAPI constructor and make a single call to handle the handshake
and retrieve user information.

Get your credentials
^^^^^^^^^^^^^^^^^^^^

`Create a Clef
application <http://docs.getclef.com/v1.0/docs/creating-a-clef-application>`__
to get your App ID and App secret

Add the Clef button
^^^^^^^^^^^^^^^^^^^

The
`button <http://docs.getclef.com/v1.0/docs/adding-the-clef-button>`__
has a ``data-redirect-url`` which is where you will handle the OAuth
callback. It can be customized or generated for you.

Usage
-----

Logging in a user
^^^^^^^^^^^^^^^^^

When a user logs in with Clef on their phone, Clef will send a code to
the redirect url you defined in the button, which is where you handle
the OAuth handshake:

::

from clef import clef

code = request.args.get("code")
api = clef.ClefAPI(app_id=YOUR_APP_ID, app_secret=YOUR_APP_SECRET)
user_info = api.get_user_info(code=code)

Logging out a user
^^^^^^^^^^^^^^^^^^

When you configure your application, you also set up a logout webhook
URL. Clef sends a POST request to this URL whenever a user who has
logged in with Clef logs out so you can handle logging out the user and
storing a logout timestamp.

::

from clef import clef

logout_token = request.form.get("logout_token")
api = clef.ClefAPI(app_id=YOUR_APP_ID, app_secret=YOUR_APP_SECRET)
clef_user_id = api.logout_user(logout_token=logout_token)

Sample App
----------

| This repo includes a one-file sample app that uses the Flask framework
and demonstrates authentication. To try it out:
| \* Install Flask if you don't already have it
| ``$ pip install Flask``
| \* Run sample\_app.py
| ``$ python sample_app.py``
| \* Visit http://localhost:5000 in your browser

The sample app doesn't handle `checking timestamped
logins <http://docs.getclef.com/v1.0/docs/checking-timestamped-logins>`__,
but there are `code
samples <http://docs.getclef.com/v1.0/docs/overview-1>`__ that
demonstrate how to do this.

Resources
---------

| Check out the `API docs <http://docs.getclef.com/v1.0/docs/>`__.
| Access your `developer dashboard <https://getclef.com/user/login>`__.

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

clef-0.0.2.tar.gz (3.7 kB view details)

Uploaded Source

File details

Details for the file clef-0.0.2.tar.gz.

File metadata

  • Download URL: clef-0.0.2.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for clef-0.0.2.tar.gz
Algorithm Hash digest
SHA256 c6175b327a5843d13d4b812270498ca0b236491559274ea3e63788dc405b4280
MD5 3389f4b5746c4d085d5514b57c7794d8
BLAKE2b-256 f6d4f474ffaf5dd71c9bd9035f42cef463e7d6d6024ebe32b36919f650f67596

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