Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reintroduce sync API. #735

Merged
merged 14 commits into from
Jan 8, 2020
9 changes: 4 additions & 5 deletions httpx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from .api import delete, get, head, options, patch, post, put, request, stream
from .auth import Auth, BasicAuth, DigestAuth
from .client import AsyncClient, Client
from .config import TimeoutConfig # For 0.8 backwards compat.
from .config import PoolLimits, Proxy, Timeout
from .dispatch.proxy_http import HTTPProxy, HTTPProxyMode
from .dispatch.asgi import ASGIDispatch
from .dispatch.wsgi import WSGIDispatch
from .exceptions import (
ConnectionClosed,
ConnectTimeout,
Expand Down Expand Up @@ -45,6 +45,7 @@
"request",
"stream",
"codes",
"ASGIDispatch",
"AsyncClient",
"Auth",
"BasicAuth",
Expand All @@ -53,9 +54,6 @@
"PoolLimits",
"Proxy",
"Timeout",
"TimeoutConfig", # For 0.8 backwards compat.
"HTTPProxy",
"HTTPProxyMode", # For 0.8 backwards compat.
"ConnectTimeout",
"CookieConflict",
"ConnectionClosed",
Expand Down Expand Up @@ -84,4 +82,5 @@
"TimeoutException",
"Response",
"DigestAuth",
"WSGIDispatch",
]
38 changes: 19 additions & 19 deletions httpx/api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import typing

from .auth import AuthTypes
from .client import AsyncClient, StreamContextManager
from .client import Client, StreamContextManager
from .config import DEFAULT_TIMEOUT_CONFIG, CertTypes, TimeoutTypes, VerifyTypes
from .models import (
CookieTypes,
Expand All @@ -15,7 +15,7 @@
)


async def request(
def request(
method: str,
url: URLTypes,
*,
Expand Down Expand Up @@ -80,10 +80,10 @@ async def request(
<Response [200 OK]>
```
"""
async with AsyncClient(
with Client(
cert=cert, verify=verify, timeout=timeout, trust_env=trust_env,
) as client:
return await client.request(
return client.request(
method=method,
url=url,
data=data,
Expand Down Expand Up @@ -114,7 +114,7 @@ def stream(
cert: CertTypes = None,
trust_env: bool = True,
) -> StreamContextManager:
client = AsyncClient(cert=cert, verify=verify, trust_env=trust_env)
client = Client(cert=cert, verify=verify, trust_env=trust_env)
request = Request(
method=method,
url=url,
Expand All @@ -135,7 +135,7 @@ def stream(
)


async def get(
def get(
url: URLTypes,
*,
params: QueryParamTypes = None,
Expand All @@ -156,7 +156,7 @@ async def get(
Note that the `data`, `files`, and `json` parameters are not available on
this function, as `GET` requests should not include a request body.
"""
return await request(
return request(
"GET",
url,
params=params,
Expand All @@ -171,7 +171,7 @@ async def get(
)


async def options(
def options(
url: URLTypes,
*,
params: QueryParamTypes = None,
Expand All @@ -192,7 +192,7 @@ async def options(
Note that the `data`, `files`, and `json` parameters are not available on
this function, as `OPTIONS` requests should not include a request body.
"""
return await request(
return request(
"OPTIONS",
url,
params=params,
Expand All @@ -207,7 +207,7 @@ async def options(
)


async def head(
def head(
url: URLTypes,
*,
params: QueryParamTypes = None,
Expand All @@ -230,7 +230,7 @@ async def head(
`HEAD` method also differs from the other cases in that `allow_redirects`
defaults to `False`.
"""
return await request(
return request(
"HEAD",
url,
params=params,
Expand All @@ -245,7 +245,7 @@ async def head(
)


async def post(
def post(
url: URLTypes,
*,
data: RequestData = None,
Expand All @@ -266,7 +266,7 @@ async def post(

**Parameters**: See `httpx.request`.
"""
return await request(
return request(
"POST",
url,
data=data,
Expand All @@ -284,7 +284,7 @@ async def post(
)


async def put(
def put(
url: URLTypes,
*,
data: RequestData = None,
Expand All @@ -305,7 +305,7 @@ async def put(

**Parameters**: See `httpx.request`.
"""
return await request(
return request(
"PUT",
url,
data=data,
Expand All @@ -323,7 +323,7 @@ async def put(
)


async def patch(
def patch(
url: URLTypes,
*,
data: RequestData = None,
Expand All @@ -344,7 +344,7 @@ async def patch(

**Parameters**: See `httpx.request`.
"""
return await request(
return request(
"PATCH",
url,
data=data,
Expand All @@ -362,7 +362,7 @@ async def patch(
)


async def delete(
def delete(
url: URLTypes,
*,
params: QueryParamTypes = None,
Expand All @@ -383,7 +383,7 @@ async def delete(
Note that the `data`, `files`, and `json` parameters are not available on
this function, as `DELETE` requests should not include a request body.
"""
return await request(
return request(
"DELETE",
url,
params=params,
Expand Down
Loading