Skip to content

Commit 87713d2

Browse files
Define and expose the API from the same place (#3106)
* Tidy up imports * Update tests/test_exported_members.py --------- Co-authored-by: Tom Christie <tom@tomchristie.com>
1 parent 77cb36f commit 87713d2

18 files changed

Lines changed: 101 additions & 44 deletions

httpx/__init__.py

Lines changed: 11 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,15 @@
11
from .__version__ import __description__, __title__, __version__
2-
from ._api import delete, get, head, options, patch, post, put, request, stream
3-
from ._auth import Auth, BasicAuth, DigestAuth, NetRCAuth
4-
from ._client import USE_CLIENT_DEFAULT, AsyncClient, Client
5-
from ._config import Limits, Proxy, Timeout, create_ssl_context
6-
from ._content import ByteStream
7-
from ._exceptions import (
8-
CloseError,
9-
ConnectError,
10-
ConnectTimeout,
11-
CookieConflict,
12-
DecodingError,
13-
HTTPError,
14-
HTTPStatusError,
15-
InvalidURL,
16-
LocalProtocolError,
17-
NetworkError,
18-
PoolTimeout,
19-
ProtocolError,
20-
ProxyError,
21-
ReadError,
22-
ReadTimeout,
23-
RemoteProtocolError,
24-
RequestError,
25-
RequestNotRead,
26-
ResponseNotRead,
27-
StreamClosed,
28-
StreamConsumed,
29-
StreamError,
30-
TimeoutException,
31-
TooManyRedirects,
32-
TransportError,
33-
UnsupportedProtocol,
34-
WriteError,
35-
WriteTimeout,
36-
)
37-
from ._models import Cookies, Headers, Request, Response
38-
from ._status_codes import codes
39-
from ._transports.asgi import ASGITransport
40-
from ._transports.base import AsyncBaseTransport, BaseTransport
41-
from ._transports.default import AsyncHTTPTransport, HTTPTransport
42-
from ._transports.mock import MockTransport
43-
from ._transports.wsgi import WSGITransport
44-
from ._types import AsyncByteStream, SyncByteStream
45-
from ._urls import URL, QueryParams
2+
from ._api import *
3+
from ._auth import *
4+
from ._client import *
5+
from ._config import *
6+
from ._content import *
7+
from ._exceptions import *
8+
from ._models import *
9+
from ._status_codes import *
10+
from ._transports import *
11+
from ._types import *
12+
from ._urls import *
4613

4714
try:
4815
from ._main import main

httpx/_api.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@
2222
VerifyTypes,
2323
)
2424

25+
__all__ = [
26+
"delete",
27+
"get",
28+
"head",
29+
"options",
30+
"patch",
31+
"post",
32+
"put",
33+
"request",
34+
"stream",
35+
]
36+
2537

2638
def request(
2739
method: str,

httpx/_auth.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
from hashlib import _Hash
1717

1818

19+
__all__ = ["Auth", "BasicAuth", "DigestAuth", "NetRCAuth"]
20+
21+
1922
class Auth:
2023
"""
2124
Base class for all authentication schemes.

httpx/_client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
same_origin,
5959
)
6060

61+
__all__ = ["USE_CLIENT_DEFAULT", "AsyncClient", "Client"]
62+
6163
# The type annotation for @classmethod and context managers here follows PEP 484
6264
# https://www.python.org/dev/peps/pep-0484/#annotating-instance-and-class-methods
6365
T = typing.TypeVar("T", bound="Client")

httpx/_config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
from ._urls import URL
1515
from ._utils import get_ca_bundle_from_env
1616

17+
__all__ = ["Limits", "Proxy", "Timeout", "create_ssl_context"]
18+
1719
DEFAULT_CIPHERS = ":".join(
1820
[
1921
"ECDHE+AESGCM",

httpx/_content.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
)
2626
from ._utils import peek_filelike_length, primitive_value_to_str
2727

28+
__all__ = ["ByteStream"]
29+
2830

2931
class ByteStream(AsyncByteStream, SyncByteStream):
3032
def __init__(self, stream: bytes) -> None:

httpx/_exceptions.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,37 @@
3838
if typing.TYPE_CHECKING:
3939
from ._models import Request, Response # pragma: no cover
4040

41+
__all__ = [
42+
"CloseError",
43+
"ConnectError",
44+
"ConnectTimeout",
45+
"CookieConflict",
46+
"DecodingError",
47+
"HTTPError",
48+
"HTTPStatusError",
49+
"InvalidURL",
50+
"LocalProtocolError",
51+
"NetworkError",
52+
"PoolTimeout",
53+
"ProtocolError",
54+
"ProxyError",
55+
"ReadError",
56+
"ReadTimeout",
57+
"RemoteProtocolError",
58+
"RequestError",
59+
"RequestNotRead",
60+
"ResponseNotRead",
61+
"StreamClosed",
62+
"StreamConsumed",
63+
"StreamError",
64+
"TimeoutException",
65+
"TooManyRedirects",
66+
"TransportError",
67+
"UnsupportedProtocol",
68+
"WriteError",
69+
"WriteTimeout",
70+
]
71+
4172

4273
class HTTPError(Exception):
4374
"""

httpx/_models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
parse_header_links,
5454
)
5555

56+
__all__ = ["Cookies", "Headers", "Request", "Response"]
57+
5658

5759
class Headers(typing.MutableMapping[str, str]):
5860
"""

httpx/_status_codes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from enum import IntEnum
44

5+
__all__ = ["codes"]
6+
57

68
class codes(IntEnum):
79
"""HTTP status codes and reason phrases

httpx/_transports/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from .asgi import *
2+
from .base import *
3+
from .default import *
4+
from .mock import *
5+
from .wsgi import *
6+
7+
__all__ = [
8+
"ASGITransport",
9+
"AsyncBaseTransport",
10+
"BaseTransport",
11+
"AsyncHTTPTransport",
12+
"HTTPTransport",
13+
"MockTransport",
14+
"WSGITransport",
15+
]

0 commit comments

Comments
 (0)