kong / py-postgrest Goto Github PK
View Code? Open in Web Editor NEWA library to work with PostgREST based APIs from Python
License: Apache License 2.0
A library to work with PostgREST based APIs from Python
License: Apache License 2.0
Hey!
We are the maintainers of supabase-py
which is the python client library for Supabase which is an open source Firebase. Supabase also uses Kong under the hood!
We'd just like to check if this library is actively being used/maintained and we would like to request for the postgrest
namespace on PyPI. We are maintaining another postgrest client library and we were are currently using the PyPI namespace postgrest_py
. We were hoping to use the postgrest
namespace(if not actively used) to complement the convention other libraries realtime
, supabase
, and gotrue
.
Totally understand if you'd prefer to keep the namespace though.
Let us know!
Joel
Objects from the python ipaddress
module should map to Postgres inet
types.
Note that the python shared ipaddress._Base_Address
class is private/undocumented
e.g. /tsearch?my_tsv=fts(french).amusant
http://postgrest.org/en/v5.2/api.html#full-text-search
So I have a role called web_anon for anonymous requests
and a role called todo_user which basically has insert/delete/update access to the database
This is how I designed my schema
CREATE SCHEMA api;
CREATE TABLE api.users(
last_name TEXT,
first_name TEXT,
user_name TEXT UNIQUE,
email TEXT UNIQUE,
has_premium BOOLEAN DEFAULT FALSE,
date_created TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
user_id BIGINT GENERATED ALWAYS AS IDENTITY
(START WITH 10000000 INCREMENT BY 1) PRIMARY KEY
);
CREATE TABLE api.passwords(
encrypted_password TEXT,
ref_user_id BIGINT,
FOREIGN KEY(ref_user_id) REFERENCES api.users(user_id) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE INDEX idx_user_id ON api.users(user_id);
CREATE INDEX idx_user_name ON api.users(user_name);
CREATE ROLE web_anon NOLOGIN;
GRANT web_anon TO postgres;
GRANT USAGE ON schema api TO web_anon;
GRANT SELECT ON api.users TO web_anon;
CREATE ROLE todo_user NOLOGIN;
GRANT todo_user TO postgres;
GRANT USAGE ON schema api To todo_user;
GRANT ALL ON api.users TO todo_user;
GRANT ALL ON api.passwords TO todo_user;
I even checked in the psql the role todo_user has the permissions as expected
So now, I want to make an insert with the python client like
sync def create_user(self, first_name, last_name, username, email, password):
"""Adds a user to the StockTools database"""
print('receiver end')
async with postgrest.Client(self.host, default_headers={"role": "todo_user"}) as client:
try:
user_insert = await client.insert("users", {'last_name': last_name, 'first_name': first_name,
'user_name': username, 'email': email},
returning='representation')
print('user insert complete')
print(user_insert)
await client.insert('passwords', {'encrypted_password': hashlib.sha3_512(password).hexdigest(),
'ref_user_id': user_insert})
print('inserted passwords')
except Exception as err:
print(err)
raise CannotManageUserData(err)
print('user created')
I cannot do this as I get the following error:
401, message='permission denied for table users', url=URL('http://localhost:3000/users')
As far as I can tell I think that the role isnt being switched into todo_user before the post request. Why?
Am I doing anything wrong? pls help me
Thanks!
Model fields should be able to be arrays.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.