Skip to content

Python script that writes dictionaries into a PostgreSQL database. Key as Column, Value as Value.

License

Notifications You must be signed in to change notification settings

pedromgsanches/py_pgsql_dict_writer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

py_pgsql_dict_writer

Script to write python dictionaries into a PostgreSQL database. I wrote this to work as a module for a in house monitoring solution in a PostgreSQL/TimeScale database.

Usage

Edit config.json

This is a JSON file, use it tell where to write:

{
 "target_database": [  
  {  
  "db": "psqlmetrics",  
  "host": "localhost",  
  "user": "postgres",  
  "port": "50000",  
  "type": "pgsql12",  
  "table_prefix": "psqlmetrics.",  
  "table_suffix": ""  
  }  
 ]  
}

Don't have a password key/value because we have client SSL connection. You should use it too instead of passwords.

Include it in your scripts:

from writetarget import target_pgsql as pgsql

Def dict as a variable in your own way

cpu_load_metrics = {  
 "hostname": "prd-superapp-01",  
 "nr_cores": "4",
 "load_pct": 67
 }

Write

Dictionary KEYS must match column names in target database.
Dictionary VALUES represent the data to write.
First argument as the Postgres target table name.

pgsql().write('cpu_load',cpu_load_metrics)

About

Python script that writes dictionaries into a PostgreSQL database. Key as Column, Value as Value.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages