Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
postgrestutils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tools
postgrestutils
Commits
380fad0e
Commit
380fad0e
authored
6 years ago
by
Fynn Becker
Browse files
Options
Downloads
Patches
Plain Diff
Close
#1
Improve configuration for python projects
parent
8384adc0
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.md
+1
-5
1 addition, 5 deletions
README.md
postgrestutils/client/postgrestclient.py
+10
-3
10 additions, 3 deletions
postgrestutils/client/postgrestclient.py
with
11 additions
and
8 deletions
README.md
+
1
−
5
View file @
380fad0e
...
...
@@ -23,12 +23,8 @@ res = pgrest_client.get("kerbals", params=payload)
##### Other projects
```
python
from
postgrestutils
import
settings
settings
.
BASE_URI
=
"
http://localhost:3000
"
settings
.
JWT
=
""
from
postgrestutils.client
import
pgrest_client
pgrest_client
.
configure
(
'
your-JWT
'
,
base_uri
=
'
http://127.0.0.1:3000
'
)
payload
=
{
"
select
"
:
"
id,forename
"
...
...
This diff is collapsed.
Click to expand it.
postgrestutils/client/postgrestclient.py
+
10
−
3
View file @
380fad0e
...
...
@@ -6,16 +6,23 @@ from postgrestutils.client.utils import datetime_parser
class
PostgrestClient
:
def
__init__
(
self
,
base_uri
,
token
):
self
.
base_uri
=
base_uri
def
__init__
(
self
,
base_uri
,
token
=
None
):
self
.
session
=
requests
.
Session
()
self
.
session
.
headers
[
"
Authorization
"
]
=
"
Bearer {}
"
.
format
(
token
)
self
.
configure
(
token
,
base_uri
=
base_uri
)
self
.
session
.
headers
[
'
Accept
'
]
=
'
application/json
'
def
configure
(
self
,
token
,
base_uri
=
None
):
if
base_uri
is
not
None
:
self
.
base_uri
=
base_uri
if
token
:
self
.
session
.
headers
[
'
Authorization
'
]
=
'
Bearer {}
'
.
format
(
token
)
def
get
(
self
,
path
,
singular
=
False
,
parse_dt
=
True
,
**
kwargs
):
"""
:param path: specifies the endpoint
:param singular: if True returns a JSON object rather than a list (406 when multiple results are returned)
:param parse_dt: if True attempts to parse datetime strings to python datetime objects
:param kwargs: pass kwargs directly to requests
'
s .get() method
:return: result(s) as python object or raises HTTPError
"""
if
singular
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment