Skip to content

Commit 1e8166d

Browse files
committed
Support basic authentication
1 parent f9ee777 commit 1e8166d

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
## CHANGELOG
22

3+
### Unreleased
4+
5+
#### Features
6+
7+
- Support basic authentication
8+
39
### v0.1.1
410

511
#### Bugfixes

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ PostgREST client for Python. This library provides an ORM interface to PostgREST
44

55
## INSTALLATION
66

7+
### Requirements
8+
9+
- Python >= 3.7
10+
- PostgreSQL >= 12
11+
- PostgREST >= 7
12+
13+
### Instructions
14+
715
## USAGE
816

917
## DOCUMENTATION

postgrest_py/client.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@ async def __aexit__(self, exc_type, exc, tb) -> None:
2222
async def aclose(self) -> None:
2323
await self.session.aclose()
2424

25-
def auth(self, token: str):
26-
self.session.headers["Authorization"] = f"Bearer {token}"
25+
def auth(self, bearer_token: str, *, username: str = None, password=""):
26+
"""Authenticate the request, with either bearer token or basic authentication."""
27+
28+
if username:
29+
self.session.auth = (username, password)
30+
else:
31+
self.session.headers["Authorization"] = f"Bearer {bearer_token}"
2732
return self
2833

2934
def schema(self, schema: str):

0 commit comments

Comments
 (0)