Skip to content

Commit 7128eb4

Browse files
author
Kenneth Reitz
committed
Merge branch 'master' into full_documentation
2 parents 2355cef + 0ba3e9c commit 7128eb4

28 files changed

Lines changed: 84 additions & 165 deletions

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
runs-on: ubuntu-latest
1616
strategy:
1717
matrix:
18-
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
18+
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
1919

2020
steps:
2121
- name: Checkout repository

HISTORY.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
Release History
22
===============
33

4-
dev
5-
---
4+
0.1.3 (2023-10-06)
5+
------------------
66

7-
* Initial release
7+
- Replace deprecated serpapi_pagination.next_link with 'next'.
8+
- Improve documentation: how to use the client directly for pagination searches.
89

9-
1.0.0 (planned)
10-
---------------
10+
0.1.2 (2023-10-03)
11+
------------------
1112

12-
- First planned release
13+
- Update project status to Production/Stable.
14+
15+
0.1.1 (2023-10-03)
16+
------------------
17+
18+
- Update documentation link to point to Read the Docs.
19+
20+
0.1.0 (2023-10-03)
21+
------------------
22+
23+
- First release on PyPI.

README.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,15 @@
33
<h1 align="center">SerpApi Python Library & Package</h1>
44
<img src="https://user-images.githubusercontent.com/78694043/233921372-bb57c347-9005-4b59-8f09-993698a87eb6.svg" width="600" alt="serpapi python library logo">
55

6-
<!-- <a href="https://badge.fury.io/py/serpapi-python">![Package](https://badge.fury.io/py/serpapi.svg)</a>
7-
<a href="https://pepy.tech/project/serpapi-python">![Downloads](https://static.pepy.tech/personalized-badge/serpapi?period=month&units=international_system&left_color=grey&right_color=brightgreen&left_text=Downloads)</a> -->
6+
<a href="https://badge.fury.io/py/serpapi-python">![Package](https://badge.fury.io/py/serpapi.svg)</a>
7+
88
[![serpapi-python](https://github.com/serpapi/serpapi-python/actions/workflows/ci.yml/badge.svg)](https://github.com/serpapi/serpapi-python/actions/workflows/ci.yml)
99
</div>
1010

1111
This repository is the home of the *soon–to–be* official Python API wrapper for [SerpApi](https://serpapi.com). This `serpapi` module allows you to access search data in your Python application.
1212

1313
[SerpApi](https://serpapi.com) supports Google, Google Maps, Google Shopping, Bing, Baidu, Yandex, Yahoo, eBay, App Stores, and more. Check out the [documentation](https://serpapi.com/search-api) for a full list.
1414

15-
## Current Status
16-
17-
This project is under development, and will be released to the public on PyPi soon.
1815

1916
## Installation
2017

@@ -24,7 +21,7 @@ To install the `serpapi` package, simply run the following command:
2421
$ pip install serpapi
2522
```
2623

27-
Please note that this package is separate from the *soon–to–be* legacy `serpapi` module, which is currently available on PyPi as `google-search-results`.
24+
Please note that this package is separate from the legacy `serpapi` module, which is available on PyPi as `google-search-results`. This package is maintained by SerpApi, and is the recommended way to access the SerpApi service from Python.
2825

2926
## Usage
3027

docs/index.rst

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.. serapi-python documentation master file, created by
1+
.. serpapi-python documentation master file, created by
22
sphinx-quickstart on Sun Apr 3 21:09:40 2022.
33
You can adapt this file completely to your liking, but it should at least
44
contain the root `toctree` directive.
@@ -37,6 +37,11 @@ For example, the API endpoint ``https://serpapi.com/search.json`` is represented
3737
3838
Any parameters that you pass to ``search()`` will be passed to the API. This includes the ``api_key`` parameter, which is required for all requests.
3939

40+
.. _using-api-client-directly:
41+
42+
Using the API Client directly
43+
^^^^^^^^^
44+
4045
To make this less repetitive, and gain the benefit of connection pooling, let's start using the API Client directly::
4146

4247
>>> client = serpapi.Client(api_key="secret_api_key")
@@ -116,9 +121,11 @@ You can get the next page of results::
116121
>>> type(s.next_page())
117122
<class 'serpapi.models.SerpResults'>
118123

119-
Or iterate over all pages of results::
124+
To iterate over all pages of results, it's recommended to :ref:`use the API Client directly <using-api-client-directly>`::
120125

121-
>>> for page in s.yield_pages():
126+
>>> client = serpapi.Client(api_key="secret_api_key")
127+
>>> search = client.search(q="Coffee", engine="google", location="Austin, Texas", hl="en", gl="us")
128+
>>> for page in search.yield_pages():
122129
... print(page["search_metadata"]["page_number"])
123130
1
124131
2

serpapi/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.0.1"
1+
__version__ = "0.1.3"

serpapi/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def next_page_url(self):
5151
serpapi_pagination = self.data.get("serpapi_pagination")
5252

5353
if serpapi_pagination:
54-
return serpapi_pagination.get("next_link")
54+
return serpapi_pagination.get("next")
5555

5656
def next_page(self):
5757
"""Return the next page of results, if any."""

setup.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,27 @@
4646
about["__version__"] = VERSION
4747

4848

49+
class TestCommand(Command):
50+
"""Support setup.py test."""
51+
52+
description = "Test the package."
53+
user_options = []
54+
55+
@staticmethod
56+
def status(s):
57+
"""Prints things in bold."""
58+
print("\033[1m{0}\033[0m".format(s))
59+
60+
def initialize_options(self):
61+
pass
62+
63+
def finalize_options(self):
64+
pass
65+
66+
def run(self):
67+
os.system("{0} -m pytest".format(sys.executable))
68+
sys.exit()
69+
4970
class UploadCommand(Command):
5071
"""Support setup.py upload."""
5172

@@ -104,7 +125,7 @@ def run(self):
104125
extras_require=EXTRAS,
105126
include_package_data=True,
106127
license="MIT",
107-
project_urls={"Documentation": "https://serpapi.com/search-api"},
128+
project_urls={"Documentation": "https://serpapi-python.readthedocs.io/en/latest/"},
108129
keywords="scrape,serp,api,serpapi,scraping,json,search,localized,rank,google,bing,baidu,yandex,yahoo,ebay,scale,datamining,training,machine,ml,youtube,naver,walmart,apple,store,app,serpapi",
109130
classifiers=[
110131
# Trove classifiers
@@ -119,6 +140,7 @@ def run(self):
119140
"Programming Language :: Python :: 3.9",
120141
"Programming Language :: Python :: 3.10",
121142
"Programming Language :: Python :: 3.11",
143+
"Programming Language :: Python :: 3.12",
122144
"Natural Language :: English",
123145
"Topic :: Utilities",
124146
"Topic :: Internet :: WWW/HTTP",
@@ -129,5 +151,6 @@ def run(self):
129151
# $ setup.py publish support.
130152
cmdclass={
131153
"upload": UploadCommand,
154+
"test": TestCommand
132155
},
133156
)

tests/example_search_apple_app_store_test.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,10 @@
33
import os
44
import serpapi
55

6-
@pytest.mark.skipif((os.getenv("API_KEY") == None), reason="no api_key provided")
7-
def test_search_apple_app_store():
8-
client = serpapi.Client(api_key=os.getenv("API_KEY"))
6+
def test_search_apple_app_store(client):
97
data = client.search({
108
'engine': 'apple_app_store',
119
'term': 'coffee',
1210
})
1311
assert data.get('error') is None
1412
assert data['organic_results']
15-
16-
# os.getenv("API_KEY") is your secret API Key
17-
# copy/paste from [http://serpapi.com/dashboard] to your bash
18-
# ```export API_KEY="your_secure_api_key"```

tests/example_search_baidu_test.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,11 @@
33
import os
44
import serpapi
55

6-
@pytest.mark.skipif((os.getenv("API_KEY") == None), reason="no api_key provided")
7-
def test_search_baidu():
8-
client = serpapi.Client(api_key=os.getenv("API_KEY"))
6+
7+
def test_search_baidu(client):
98
data = client.search({
109
'engine': 'baidu',
1110
'q': 'coffee',
1211
})
1312
assert data.get('error') is None
1413
assert data['organic_results']
15-
16-
# os.getenv("API_KEY") is your secret API Key
17-
# copy/paste from [http://serpapi.com/dashboard] to your bash
18-
# ```export API_KEY="your_secure_api_key"```

tests/example_search_bing_test.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,10 @@
33
import os
44
import serpapi
55

6-
@pytest.mark.skipif((os.getenv("API_KEY") == None), reason="no api_key provided")
7-
def test_search_bing():
8-
client = serpapi.Client(api_key=os.getenv("API_KEY"))
6+
def test_search_bing(client):
97
data = client.search({
108
'engine': 'bing',
119
'q': 'coffee',
1210
})
1311
assert data.get('error') is None
1412
assert data['organic_results']
15-
16-
# os.getenv("API_KEY") is your secret API Key
17-
# copy/paste from [http://serpapi.com/dashboard] to your bash
18-
# ```export API_KEY="your_secure_api_key"```

0 commit comments

Comments
 (0)