├── .gitignore ├── README.md ├── googlebooks.py └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.py[co] 2 | 3 | # Packages 4 | *.egg 5 | *.egg-info 6 | dist 7 | build 8 | eggs 9 | parts 10 | bin 11 | var 12 | sdist 13 | develop-eggs 14 | .installed.cfg 15 | 16 | # Installer logs 17 | pip-log.txt 18 | 19 | # Unit test / coverage reports 20 | .coverage 21 | .tox 22 | 23 | #Translations 24 | *.mo 25 | 26 | #Mr Developer 27 | .mr.developer.cfg 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | googlebooks 2 | =========== 3 | 4 | [Google Books API][api] search access with Python. Anonymous Access is rate limited 5 | by google. An alternative is the [python google data api][gdata]. 6 | 7 | [api]: https://developers.google.com/books/ 8 | [gdata]: http://code.google.com/p/gdata-python-client/ 9 | 10 | 11 | ```python 12 | import googlebooks 13 | api = googlebooks.Api() 14 | api.list('isbn:0596007973') 15 | ``` 16 | 17 | Returns the following json response 18 | ```json 19 | { 20 | "totalItems": 1, 21 | "items": [ 22 | { 23 | "kind": "books#volume", 24 | "volumeInfo": { 25 | "publisher": "O'Reilly Media", 26 | "description": "Demonstrates the programming language's strength as a Web development tool, covering syntax, data types, built-ins, the Python standard module library, and real-world examples.", 27 | "language": "en", 28 | "publishedDate": "2005-03-18", 29 | "imageLinks": { 30 | "smallThumbnail": "http://bks9.books.google.de/books?id=1Shx_VXS6ioC&printsec=frontcover&img=1&zoom=5&edge=curl&source=gbs_api", 31 | "thumbnail": "http://bks9.books.google.de/books?id=1Shx_VXS6ioC&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api" 32 | }, 33 | "previewLink": "http://books.google.de/books?id=1Shx_VXS6ioC&printsec=frontcover&dq=isbn:0596007973&hl=&cd=1&source=gbs_api", 34 | "title": "Python Cookbook", 35 | "printType": "BOOK", 36 | "pageCount": 807, 37 | "canonicalVolumeLink": "http://books.google.de/books/about/Python_Cookbook.html?hl=&id=1Shx_VXS6ioC", 38 | "contentVersion": "0.1.0.0.preview.3", 39 | "industryIdentifiers": [ 40 | { 41 | "identifier": "0596007973", 42 | "type": "ISBN_10" 43 | }, 44 | { 45 | "identifier": "9780596007973", 46 | "type": "ISBN_13" 47 | } 48 | ], 49 | "authors": [ 50 | "Alex Martelli", 51 | "Anna Martelli Ravenscroft", 52 | "David Ascher" 53 | ], 54 | "ratingsCount": 21, 55 | "infoLink": "http://books.google.de/books?id=1Shx_VXS6ioC&dq=isbn:0596007973&hl=&source=gbs_api", 56 | "categories": [ 57 | "Computers" 58 | ], 59 | "averageRating": 3.5 60 | }, 61 | "searchInfo": { 62 | "textSnippet": "Demonstrates the programming language's strength as a Web development tool, covering syntax, data types, built-ins, the Python standard module library, and real-world examples." 63 | }, 64 | "saleInfo": { 65 | "country": "DE", 66 | "saleability": "NOT_FOR_SALE", 67 | "isEbook": false 68 | }, 69 | "etag": "jd9A6ca9s2s", 70 | "accessInfo": { 71 | "webReaderLink": "http://books.google.de/books/reader?id=1Shx_VXS6ioC&hl=&printsec=frontcover&output=reader&source=gbs_api", 72 | "publicDomain": false, 73 | "embeddable": true, 74 | "country": "DE", 75 | "textToSpeechPermission": "ALLOWED_FOR_ACCESSIBILITY", 76 | "pdf": { 77 | "isAvailable": true 78 | }, 79 | "viewability": "PARTIAL", 80 | "epub": { 81 | "isAvailable": true 82 | }, 83 | "accessViewStatus": "SAMPLE" 84 | }, 85 | "id": "1Shx_VXS6ioC", 86 | "selfLink": "https://www.googleapis.com/books/v1/volumes/1Shx_VXS6ioC" 87 | } 88 | ], 89 | "kind": "books#volumes" 90 | } 91 | ``` 92 | -------------------------------------------------------------------------------- /googlebooks.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import json 3 | 4 | class Api(object): 5 | """Google Books Api 6 | 7 | See: https://developers.google.com/books/ 8 | """ 9 | __BASEURL = 'https://www.googleapis.com/books/v1' 10 | def __init__(self ): 11 | pass 12 | 13 | def _get(self, path, params=None): 14 | if params is None: 15 | params = {} 16 | resp = requests.get(self.__BASEURL+path, params=params) 17 | if resp.status_code == 200: 18 | return json.loads(resp.content) 19 | 20 | return resp 21 | 22 | def get(self, volumeId, **kwargs): 23 | """Retrieves a Volume resource based on ID 24 | 25 | volumeId -- ID of volume to retrieve. 26 | 27 | Optional Parameters: 28 | 29 | partner -- Brand results for partner ID. 30 | 31 | projection -- Restrict information returned to a set of selected fields. 32 | 33 | Acceptable values are: 34 | "full" - Includes all volume data. 35 | "lite" - Includes a subset of fields in volumeInfo and accessInfo. 36 | 37 | source -- String to identify the originator of this request. 38 | 39 | See: https://developers.google.com/books/docs/v1/reference/volumes/get 40 | """ 41 | path = '/volumes/'+volumeId 42 | params = dict() 43 | for p in 'partner projection source'.split(): 44 | if p in kwargs: 45 | params[p] = kwargs[p] 46 | 47 | return self._get(path) 48 | 49 | def list(self, q, **kwargs): 50 | """Performs a book search. 51 | 52 | q -- Full-text search query string. 53 | 54 | There are special keywords you can specify in the search terms to 55 | search in particular fields, such as: 56 | 57 | intitle: Returns results where the text following this keyword is 58 | found in the title. 59 | inauthor: Returns results where the text following this keyword is 60 | found in the author. 61 | inpublisher: Returns results where the text following this keyword 62 | is found in the publisher. 63 | subject: Returns results where the text following this keyword is 64 | listed in the category list of the volume. 65 | isbn: Returns results where the text following this keyword is the 66 | ISBN number. 67 | lccn: Returns results where the text following this keyword is the 68 | Library of Congress Control Number. 69 | oclc: Returns results where the text following this keyword is the 70 | Online Computer Library Center number. 71 | 72 | Optional Parameters: 73 | 74 | download -- Restrict to volumes by download availability. 75 | 76 | Acceptable values are: 77 | "epub" - All volumes with epub. 78 | 79 | filter -- Filter search results. 80 | 81 | Acceptable values are: 82 | "ebooks" - All Google eBooks. 83 | "free-ebooks" - Google eBook with full volume text viewability. 84 | "full" - Public can view entire volume text. 85 | "paid-ebooks" - Google eBook with a price. 86 | "partial" - Public able to see parts of text. 87 | 88 | langRestrict -- Restrict results to books with this language code. 89 | 90 | libraryRestrict -- Restrict search to this user's library. 91 | 92 | Acceptable values are: 93 | "my-library" - Restrict to the user's library, any shelf. 94 | "no-restrict" - Do not restrict based on user's library. 95 | 96 | maxResults -- Maximum number of results to return. Acceptable values are 0 to 40, inclusive. 97 | 98 | orderBy -- Sort search results. 99 | 100 | Acceptable values are: 101 | "newest" - Most recently published. 102 | "relevance" - Relevance to search terms. 103 | 104 | partner -- Restrict and brand results for partner ID. 105 | 106 | printType -- Restrict to books or magazines. 107 | 108 | Acceptable values are: 109 | "all" - All volume content types. 110 | "books" - Just books. 111 | "magazines" - Just magazines. 112 | 113 | projection -- Restrict information returned to a set of selected fields. 114 | 115 | Acceptable values are: 116 | "full" - Includes all volume data. 117 | "lite" - Includes a subset of fields in volumeInfo and accessInfo. 118 | 119 | showPreorders -- Set to true to show books available for preorder. Defaults to false. 120 | 121 | source -- String to identify the originator of this request. 122 | 123 | startIndex -- Index of the first result to return (starts at 0) 124 | 125 | See: https://developers.google.com/books/docs/v1/reference/volumes/list 126 | """ 127 | path = '/volumes' 128 | params = dict(q=q) 129 | for p in 'download filter langRestrict libraryRestrict maxResults orderBy partner printType projection showPreorders source startIndex'.split(): 130 | if p in kwargs: 131 | params[p] = kwargs[p] 132 | 133 | return self._get(path, params) 134 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from distutils.core import setup 4 | 5 | setup(name='googlebooks', 6 | version='1.0', 7 | description='Google Books Api', 8 | author='Peter Hoffmann', 9 | author_email='ph@peter-hoffmann.com', 10 | url='http://www.python.org/sigs/distutils-sig/', 11 | py_modules=['googlebooks'], 12 | ) 13 | --------------------------------------------------------------------------------