1
- from typing import Union
1
+ from typing import Dict , Union
2
2
3
3
from deprecation import deprecated
4
4
from httpx import AsyncClient , BasicAuth , Response
5
5
6
6
from postgrest_py .__version__ import __version__
7
7
from postgrest_py .request_builder import RequestBuilder
8
8
9
+ DEFAULT_POSTGREST_CLIENT_HEADERS : Dict [str , str ] = {
10
+ "Accept" : "application/json" ,
11
+ "Content-Type" : "application/json" ,
12
+ }
13
+
9
14
10
15
class PostgrestClient :
11
16
"""PostgREST client."""
12
17
13
- def __init__ (self , base_url : str , * , schema = "public" ) -> None :
18
+ def __init__ (
19
+ self ,
20
+ base_url : str ,
21
+ * ,
22
+ schema : str = "public" ,
23
+ headers : Dict [str , str ] = DEFAULT_POSTGREST_CLIENT_HEADERS ,
24
+ ) -> None :
14
25
headers = {
15
- "Accept" : "application/json" ,
16
- "Content-Type" : "application/json" ,
26
+ ** headers ,
17
27
"Accept-Profile" : schema ,
18
28
"Content-Profile" : schema ,
19
29
}
@@ -32,7 +42,7 @@ def auth(
32
42
self ,
33
43
token : str ,
34
44
* ,
35
- username : Union [str , bytes ] = None ,
45
+ username : Union [str , bytes , None ] = None ,
36
46
password : Union [str , bytes ] = "" ,
37
47
):
38
48
"""Authenticate the client with either bearer token or basic authentication."""
@@ -44,9 +54,7 @@ def auth(
44
54
45
55
def schema (self , schema : str ):
46
56
"""Switch to another schema."""
47
- self .session .headers .update (
48
- {"Accept-Profile" : schema , "Content-Profile" : schema }
49
- )
57
+ self .session .headers .update ({"Accept-Profile" : schema , "Content-Profile" : schema })
50
58
return self
51
59
52
60
def from_ (self , table : str ) -> RequestBuilder :
0 commit comments