PYCOF
PYCOF is a library to group some useful functions on Python. The library helps running SQL queries or send emails in a much simpler way.
The library is pip-installable and the source code is available on my Git. For any question or suggestion of improvement, please contact me.
Installation
You can get PYCOF from PyPI with:
pip3 install pycof
The library is supported on Windows, Linux and MacOS.
Setup
1. AWS credentials setup
Some functions such as pycof.sql.remote_execute_sql()
, pycof.data.f_read()
or pycof.misc.write()
may need to have access to AWS to intereact with different services.
On a AWS instance (e.g. EC2, SageMaker), you may not need to got though these steps as the instance would directly consume the IAM role you assigned to it.
Then, on a local instance (which will rely on a IAM user), run:
aws configure
and enter your AWS access and private keys.
Note that this setup is required only if you use AWS services such as S3 or Redshift. These functions also work without credentials for local use.
2. PYCOF configuration setup
The functions pycof.sql.remote_execute_sql()
and pycof.format.send_email()
will, by default, look for the credentials located in /etc/.pycof/config.json
.
On Windows, save the config file as C:/Users/<username>/.pycof/config.json
.
The file follows the below structure:
{
"DB_USER": "",
"DB_PASSWORD": "",
"DB_HOST": "",
"DB_PORT": "3306",
"DB_DATABASE": "",
"__COMMENT_1__": "Email specific, send_email",
"EMAIL_USER": "",
"EMAIL_SENDER": "",
"EMAIL_PASSWORD": "",
"EMAIL_SMTP": "smtp.gmail.com",
"EMAIL_PORT": "587",
"__COMMENT_2__": "IAM specific, if connection='SSH' in remote_execute_sql",
"CLUSTER_NAME": "",
"__COMMENT_3__": "SSH specific",
"SSH_USER": "",
"SSH_KEY": "",
"SSH_PASSWORD": ""
}
On Unix based system, run:
sudo nano /etc/.pycof/config.json
and paste the above json after filling the empty strings (pre-filled values are standard default values).
Reminder: To save the file, with nano press CTRL + O
, confirm with ENTER
then CTRL + X
to exit.
Available functions
SQL
Data
Formatting
Release and FAQ
- Library updates
- 1.5.0 - September 25, 2022 - Custom cache folder in
pycof.sql.remote_execute_sql()
and write supports json files - 1.3.0 - May 23, 2021 - AWS credentials profile prioritized over config file
- 1.2.5 - February 2, 2021 - Emails and Google Calendar are now supported
- 1.2.0 - December 13, 2020 - SSH tunnels supported in
pycof.sql.remote_execute_sql()
- 1.1.37 - September 30, 2020 - SQLite database on
pycof.sql.remote_execute_sql()
- 1.1.35 - September 13, 2020 - Connector engine added to
pycof.sql.remote_execute_sql()
- 1.1.33 - May 17, 2020 - Improved query experience with
pycof.sql.remote_execute_sql()
- 1.1.26 - Mar 20, 2020 -
pycof.data.f_read()
now supports json and parquet - 1.1.21 - Feb 21, 2020 - New function
pycof.data.f_read()
- 1.1.13 - Dec 21, 2019 - New function
pycof.send_email()
- 1.1.11 - Dec 10, 2019 -
pycof.sql.remote_execute_sql()
now supports caching - 1.1.9 - Nov 23, 2019 -
pycof.sql.remote_execute_sql()
now supports COPY - 1.1.5 - Nov 15, 2019 -
pycof.sql.remote_execute_sql()
now supprots IAM credentials
- 1.5.0 - September 25, 2022 - Custom cache folder in
- FAQ
- I have an error when using a function, what can I do?
- I am having issues when installing pycof on Windows, is this a known issue?
- I am having issues with the Google dependencies, how can I fix?
- What if I change an argument in the SQL query and run with
cache='1h'
? - How to use different credential sets?
- How to execute a query from an SQL file?
- How to query with AWS IAM credentials?
- How to cache the data?
- How to query a database with SSH tunneling?
- How can I load a .json file as a dictionnary?
- How can I read .parquet files?
- How can I get my AWS credentials with boto3?