Skip to content

Commit 079a887

Browse files
committed
Use httpx instead of requests
1 parent bec4bec commit 079a887

File tree

10 files changed

+21
-22
lines changed

10 files changed

+21
-22
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Maintenance
66

77
* Removed `requirements.txt`; it was unnecessary and out of date
8+
* Replaced `requests` dependency with `httpx`
89

910

1011
## [v1.10.0]

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Questions about PyDelphin can be asked on the [DELPH-IN Discourse
1919
site](https://delphinqa.ling.washington.edu/) in the "PyDelphin Tools"
2020
category.
2121

22-
For bug requests, please provide the following, if possible:
22+
For bug reports, please provide the following, if possible:
2323

2424
* a minimal working example
2525
* version of PyDelphin (and relevant dependencies)

delphin/web/client.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from urllib.parse import urljoin
77

8-
import requests
8+
import httpx
99

1010
from delphin import interface
1111

@@ -60,7 +60,7 @@ def interact(self, datum, params=None, headers=None):
6060
A Response containing the results, if the request was
6161
successful.
6262
Raises:
63-
requests.HTTPError: if the status code was not 200
63+
httpx.HTTPError: if the status code was not 200
6464
"""
6565
if params is None:
6666
params = {}
@@ -71,11 +71,10 @@ def interact(self, datum, params=None, headers=None):
7171
hdrs.update(headers)
7272

7373
url = urljoin(self.server, self.task)
74-
r = requests.get(url, params=params, headers=hdrs)
75-
if r.status_code == 200:
76-
return _HTTPResponse(r.json())
77-
else:
78-
r.raise_for_status()
74+
with httpx.Client() as client:
75+
r = client.get(url, params=params, headers=hdrs)
76+
r.raise_for_status()
77+
return _HTTPResponse(r.json())
7978

8079
def process_item(self, datum, keys=None, params=None, headers=None):
8180
"""
@@ -132,7 +131,7 @@ def parse(input, server=DEFAULT_SERVER, params=None, headers=None):
132131
A Response containing the results, if the request was
133132
successful.
134133
Raises:
135-
requests.HTTPError: if the status code was not 200
134+
httpx.HTTPError: if the status code was not 200
136135
"""
137136
return next(parse_from_iterable([input], server, params, headers), None)
138137

@@ -154,7 +153,7 @@ def parse_from_iterable(
154153
Yields:
155154
Response objects for each successful response.
156155
Raises:
157-
requests.HTTPError: for the first response with a status code
156+
httpx.HTTPError: for the first response with a status code
158157
that is not 200
159158
"""
160159
client = Parser(server)
@@ -176,7 +175,7 @@ def generate(input, server=DEFAULT_SERVER, params=None, headers=None):
176175
A Response containing the results, if the request was
177176
successful.
178177
Raises:
179-
requests.HTTPError: if the status code was not 200
178+
httpx.HTTPError: if the status code was not 200
180179
"""
181180
return next(generate_from_iterable([input], server, params, headers), None)
182181

@@ -198,7 +197,7 @@ def generate_from_iterable(
198197
Yields:
199198
Response objects for each successful response.
200199
Raises:
201-
requests.HTTPError: for the first response with a status code
200+
httpx.HTTPError: for the first response with a status code
202201
that is not 200
203202
"""
204203
client = Generator(server)

delphin/web/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def configure(api, parser=None, generator=None, testsuites=None):
3737
:class:`GenerationServer` instances directly.
3838
3939
Args:
40-
api: an instance of :class:`falcon.API`
40+
api: an instance of :class:`falcon.App`
4141
parser: a path to a grammar or a :class:`ParseServer` instance
4242
generator: a path to a grammar or a :class:`GenerationServer`
4343
instance

docs/api/delphin.web.client.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ servers that implement the DELPH-IN Web API described here:
1111

1212
.. note::
1313

14-
Requires `requests` (https://pypi.python.org/pypi/requests). This
14+
Requires `httpx` (https://www.python-httpx.org/). This
1515
dependency is satisfied if you install PyDelphin with the ``[web]``
1616
extra (see :doc:`../guides/setup`).
1717

docs/api/delphin.web.server.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ such as the following example:
2929
3030
from delphin.web import server
3131
32-
application = falcon.API()
32+
application = falcon.App()
3333
3434
server.configure(
3535
application,

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@
187187
# Example configuration for intersphinx: refer to the Python standard library.
188188
intersphinx_mapping = {
189189
'python': ('https://docs.python.org/3', None),
190-
'requests': ('https://requests.readthedocs.io/en/master/', None),
190+
# 'httpx': ('https://www.python-httpx.org/', None),
191191
'falcon': ('https://falcon.readthedocs.io/en/2.0.0/', None)
192192
}
193193

docs/guides/setup.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Module or Function Dependencies Notes
2828
================================= ============ ===========================
2929
:mod:`delphin.ace` ACE_ Linux and Mac only
3030
:mod:`delphin.highlight` Pygments_
31-
:mod:`delphin.web.client` requests_ ``[web]`` extra
31+
:mod:`delphin.web.client` httpx_ ``[web]`` extra
3232
:mod:`delphin.web.server` Falcon_ ``[web]`` extra
3333
:mod:`delphin.codecs.dmrspenman` Penman_
3434
:mod:`delphin.codecs.edspenman` Penman_
@@ -41,7 +41,7 @@ are not listed in the table above).
4141

4242
.. _ACE: http://sweaglesw.org/linguistics/ace/
4343
.. _Pygments: https://pygments.org/
44-
.. _requests: http://python-requests.org/
44+
.. _httpx: https://www.python-httpx.org/
4545
.. _Falcon: https://falcon.readthedocs.io/
4646
.. _Penman: https://github.com/goodmami/penman
4747
.. _regex: https://bitbucket.org/mrabarnett/mrab-regex/

docs/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
sphinx
22
sphinx-rtd-theme
3-
requests
3+
httpx
44
falcon

pyproject.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ dependencies = [
4040
[project.optional-dependencies]
4141
web = [
4242
"falcon",
43-
"requests",
43+
"httpx",
4444
]
4545
repp = [
4646
"regex"
@@ -69,7 +69,6 @@ dependencies = [
6969
"pytest",
7070
"ruff",
7171
"mypy",
72-
"types-requests",
7372
]
7473
[tool.hatch.envs.dev.scripts]
7574
test = "pytest {args:.}"
@@ -80,7 +79,7 @@ typecheck = "mypy --namespace-packages --explicit-package-bases --ignore-missing
8079
dependencies = [
8180
"sphinx",
8281
"sphinx-rtd-theme",
83-
"requests",
82+
"httpx",
8483
"falcon",
8584
]
8685
[tool.hatch.envs.docs.scripts]

0 commit comments

Comments
 (0)