https://github.com/segasai/pginpy
The module to start a temporary Postgresql instance from python and run queries against it.
https://github.com/segasai/pginpy
postgresql query
Last synced: about 2 months ago
JSON representation
The module to start a temporary Postgresql instance from python and run queries against it.
- Host: GitHub
- URL: https://github.com/segasai/pginpy
- Owner: segasai
- License: bsd-3-clause
- Created: 2021-01-17T05:09:37.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2021-01-28T17:43:09.000Z (over 5 years ago)
- Last Synced: 2025-03-18T16:04:32.561Z (over 1 year ago)
- Topics: postgresql, query
- Language: Python
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# pginpy
Python module to start a temporary instance of postgres to run queries against
Author: Sergey Koposov (Uni of Cambridge/CMU/Uni of Edinburgh)
## Installation
To install the package you just need to do pip install pginpy
```
pip install pginpy
```
After installing my suggestion is to use sqlutilpy to query the database, but you
can use standard psycopg2
```python
import pginpy
import sqlutilpy
# start server in the temp directory, we specifiy the prefix to PG binaries if needed
S = pginpy.PGServer(prefix='/home/koposov/bighome/soft/pginstall13/bin/')
# get the connection
conn=S.getConnection()
# upload stuff in PG using sqlutilpy
sqlutilpy.upload('tab',{'id':np.arange(100),'y':np.arange(100)**.4},conn=conn)
# Run arbitrary queries against it
ID,avgy=sqlutilpy.get(''' select id, avg(y) from tab group by id''',conn=conn)
# stop the server if needed
S.stop()
```