Python module for connect with PostgreSQL and ClickHouse
Project description
Connector to databases
Connector to databases – easy package for connect with database PostgreSQL and ClickHouse
Installation
Install the current version with PyPI:
pip install connectors-to-databases
Or from GitHub:
pip install https://github.com/k0rsakov/connectors_to_databases/archive/refs/heads/main.zip
How to use class PostgreSQL
Creating instance of class
You can create as many database connectors as you want.
from connectors_to_databases import PostgreSQL
pg = PostgreSQL()
pg_other = PostgreSQL(
host='0.0.0.0',
port=0,
database='main',
login='admin',
password='admin',
)
Check connection to database
pg.check_connection()
Creating a table for examples
pg.execute_script('CREATE TABLE simple_ (id int4)')
Filling the table with data
# simple pd.DataFrame
df = pd.DataFrame(data={'id':[1]})
pg.insert_df(
df=df,
pg_table_name='simple_'
)
Getting data from a table
pg.execute_to_df(
'''select * from simple_'''
)
Getting a connector to the database.
It can be used as you need.
pg.get_uri()
What does the connector look like
Engine(postgresql://postgres:***@localhost:5432/postgres)
Delete our simple_
table
pg.execute_script('DROP TABLE simple_')
How to use class ClickHouse
Creating instance of class
You can create as many database connectors as you want.
from connectors_to_databases import ClickHouse
ch = ClickHouse()
ch_other = ClickHouse(
host='0.0.0.0',
port=0,
login='admin',
password='admin',
)
Creating a table for examples
ch.execute_script(
'''
CREATE TABLE test
(
value Int64
)
ENGINE = MergeTree
ORDER BY value
'''
)
Filling the table with data
# simple pd.DataFrame
df = ch.DataFrame(data={'value':[1]})
ch.insert_df(
df=df,
pg_table_name='test'
)
Getting data from a table
ch.execute_to_df(
'''select * from test'''
)
Getting a connector to the database.
It can be used as you need.
ch.get_uri()
What does the connector look like
Engine(clickhouse://click:***@localhost:8123/default)
Delete our simple_
table
ch.execute_script('DROP TABLE test')
Contributing
Bug reports and/or pull requests are welcome
License
The module is available as open source under the terms of the Apache License, Version 2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for connectors_to_databases-1.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0aa830bb9251c6043ef62671468d8cc3addd09f69194874b40f20fee3791737 |
|
MD5 | 4badefde0d8ea79f5c473d52b55c1afa |
|
BLAKE2b-256 | 626fe0e3a35961955f344bfbe291951b9d1d5f0a61d9e59557c02f5b61776e49 |
Close
Hashes for connectors_to_databases-1.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aff1aec6258d01c49e8be258dc4b560c64a7839f3e20cae292d2198fc8bbbd49 |
|
MD5 | d374714b8101bac74e591e1cda85a242 |
|
BLAKE2b-256 | 255d2d8eadb64c43de4a840ca5248d6f904907a70e8f9e4bdf2257992bb09e26 |