pip install txpostgres
pip install twisted
python
from twisted.internet import defer
from twisted.internet import reactor
from txpostgres import txpostgres
conn = txpostgres.Connection()
params = {
'user': 'your_username',
'password': 'your_password',
'database': 'your_database',
'host': 'your_host',
'port': 'your_port'
}
@defer.inlineCallbacks
def connect():
yield conn.connect(**params)
print("Connected to PostgreSQL")
result = yield conn.runQuery("SELECT * FROM your_table")
print("Query result:", result)
yield conn.close()
print("Connection closed")
connect().addCallback(lambda _: reactor.stop())
reactor.run()