goodreads_api_client¶
A lightweight wrapper around the Goodreads API
Quickstart Guide¶
Step-by-step instructions for getting started with goodreads_api_client.
Quickstart Guide¶
Eager to get started? This page gives a good introduction in how to get started with goodreads_api_client.
Installation¶
First, make sure you have goodreads_api_client installed:
$ pip install goodreads_api_client
Now let’s get started with a simple example.
Basic Usage¶
Make sure you have a Goodreads developer key first
Begin by importing the goodreads_api_client module:
>>> import goodreads_api_client as gr
Create a client:
>>> client = gr.Client(developer_key='<YOUR_DEVELOPER_KEY>')
Call the API:
>>> book = client.Book.show('1128434')
This will give you back an OrderedDict with the contents of the Goodreads API response, minus some generally useless request metadata. That means you could do a transformation like:
>>> keys_wanted = ['id', 'title', 'isbn']
>>> reduced_book = {k:v for k, v in book.items() if k in keys_wanted}
>>> reduced_book
{'id': '1128434', 'title': 'The Last Wish (The Witcher, #1)', 'isbn': '0575077832'}
Book
is just one of many resources
goodreads_api_client supports. For the full list, see Resources.
For the methods available for a given resource, see the individual resource class.
Oauth Usage¶
Some Goodreads API endpoints are only available by using OAuth.
Begin by importing the goodreads_api_client module:
>>> import goodreads_api_client as gr
Create a client:
>>> client = gr.Client(developer_key='<YOUR_DEVELOPER_KEY>',
developer_secret='<YOUR_DEVELOPER_SECRET>')
Authorize the client (this will open up your browser if you have not authenticated against Goodreads before and stored your credentials):
>>> client.authorize()
Call the API:
>>> rec = client.Recommendation.show('25047806')
API Documentation¶
Documentation on specific functions, classes, and methods.
API Documentation¶
Goodreads API Client¶
Goodreads API Client is a non-official Python client for Goodreads <http://www.goodreads.com/>.
This part of the documentation covers the interfaces of goodreads_api_client.
Main Interface¶
You’ll primarily use goodreads_api_client via the Client
it provides.
-
class
goodreads_api_client.
Client
(developer_key: str, developer_secret: str = None, base_url: str = None)[source]¶ Makes API Calls to the Goodreads API <https://goodreads.com/api>.
All other endpoints are provided through resource attributes on the Client
Resources¶
goodreads_api_client.resources¶
Holds classes for each Goodreads API Resource a user can interact with via the Goodreads API
-
class
goodreads_api_client.resources.
Author
(transport=None)[source]¶ Bases:
goodreads_api_client.resources.base.Resource
-
resource_name
= 'author'¶
-
-
class
goodreads_api_client.resources.
Book
(transport=None)[source]¶ Bases:
goodreads_api_client.resources.base.Resource
-
resource_name
= 'book'¶
-
-
class
goodreads_api_client.resources.
Comment
(transport=None)[source]¶ Bases:
goodreads_api_client.resources.base.Resource
-
class
goodreads_api_client.resources.
Event
(transport=None)[source]¶ Bases:
goodreads_api_client.resources.base.Resource
-
resource_name
= 'event'¶
-
-
class
goodreads_api_client.resources.
Group
(transport=None)[source]¶ Bases:
goodreads_api_client.resources.base.Resource
-
resource_name
= 'group'¶
-
-
class
goodreads_api_client.resources.
ReadStatus
(transport=None)[source]¶ Bases:
goodreads_api_client.resources.base.Resource
-
resource_name
= 'read_status'¶
-
-
class
goodreads_api_client.resources.
Recommendation
(transport=None)[source]¶ Bases:
goodreads_api_client.resources.base.Resource
-
class
goodreads_api_client.resources.
Review
(transport=None)[source]¶ Bases:
goodreads_api_client.resources.base.Resource
-
resource_name
= 'review'¶
-
-
class
goodreads_api_client.resources.
Series
(transport=None)[source]¶ Bases:
goodreads_api_client.resources.base.Resource
-
resource_name
= 'series'¶
-
-
class
goodreads_api_client.resources.
Shelf
(transport=None)[source]¶ Bases:
goodreads_api_client.resources.base.Resource
-
class
goodreads_api_client.resources.
Topic
(transport=None)[source]¶ Bases:
goodreads_api_client.resources.base.Resource
-
resource_name
= 'topic'¶
-
Lower-Level Classes¶
-
class
goodreads_api_client.transport.
Transport
(developer_key: str, developer_secret: str = None, base_url: str = None)[source]¶ Makes requests to Goodreads API and applies transform to response.
-
access_token_url
¶
-
gr
¶
-
req
(method: str = 'GET', endpoint: str = None, params: dict = None, data: dict = None, transform: str = 'xml', uses_oauth: bool = False)[source]¶
-
request_token_url
¶
-
session
¶
-
Exceptions¶
goodreads_api_client.exceptions¶
Contains goodreads_api_client’s exceptions.
-
exception
goodreads_api_client.exceptions.
GoodreadsApiClientException
[source]¶ Bases:
Exception
Base exception
-
exception
goodreads_api_client.exceptions.
OauthEndpointNotImplemented
[source]¶ Bases:
goodreads_api_client.exceptions.GoodreadsApiClientException
OAuth not yet supported by this library
-
exception
goodreads_api_client.exceptions.
ExtraApiPermissionsRequired
[source]¶ Bases:
goodreads_api_client.exceptions.GoodreadsApiClientException
Must contact Goodreads for extra perms to use endpoint
Contributor Guide¶
Guide to contributing to goodreads_api_client.
Contributor’s Guide¶
goodreads_api_client is under active development, and contributions are more than welcome!
- See open issues on Github
- Create a pull request against the master branch and tag @mdzhang for review
- Once you get a :+1: and all CI checks are passing, go ahead and merge
Updating Tests¶
This library uses VCR for recording Goodreads API responses to use during tests. When adding new tests, you should add new API response recordings, aka cassettes. To record new cassettes, you’ll need
- a Goodreads developer key
- to put your keys into GOODREADS_API_KEY and GOODREADS_API_SECRET environment variables, using something like direnv
- to blow away old cassettes (if necessary)
- to re-run make test to re-record cassettes
For Oauth tests, you also want to
- Run client.authorize() locally (e.g. from a Python REPL) to generate a client.json file
#. to uncomment the test patch blocking triggering the Oauth setup flow in <goodreads_api_client/tests/resources/conftest.py>
, specifically the patch_transport.start() line
# to re-run make test to re-record cassettes
And that should be it.
Code Linting¶
The CI is currently setup to lint all files, but you can also use Yelp’s pre-commit to run lint checks as pre-commit hooks