capitalone/locopy
capitalone/locopy has 114 GitHub stars and 53 forks. GitHot measured 0 stars in 24 hours and 0 in 7 days. Last checked 2026-11-14 00:40 UTC. Last push 2026-11-02.
Progression mesurée des étoiles
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- Historique en cours
- in 1 month
- Historique en cours
Variations nettes sur des périodes qui se chevauchent, pas des totaux quotidiens. Les mesures absentes restent vides. Les étoiles indiquent l’intérêt, pas la qualité.
À propos
locopy: Loading/Unloading to Redshift and Snowflake using Python.
DonnéesREADME.md
Original.. image:: https://img.shields.io/pypi/pyversions/locopy :target: https://pypi.org/project/locopy/ :alt: PyPI - Python Version .. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json :target: https://github.com/astral-sh/ruff :alt: Ruff .. image:: https://badge.fury.io/py/locopy.svg :target: https://badge.fury.io/py/locopy :alt: PyPI version .. image:: https://anaconda.org/conda-forge/locopy/badges/version.svg :target: https://anaconda.org/conda-forge/locopy :alt: conda-forge version .. image:: https://img.shields.io/pypi/dm/locopy :target: https://pypistats.org/packages/locopy :alt: PyPI - Downloads
locopy: Data Load and Copy using Python
A Python library to assist with ETL processing for:
- Amazon Redshift (
COPY,UNLOAD) - Snowflake (
COPY INTO <table>,COPY INTO <location>)
In addition:
- The library supports Python 3.10 to 3.13
- DB Driver (Adapter) agnostic. Use your favourite driver that complies with
DB-API 2.0 <https://www.python.org/dev/peps/pep-0249/>_ - It provides functionality to download and upload data to S3 buckets, and internal stages (Snowflake)
Quick Installation
.. code-block:: bash
pip install locopy
or install from conda-forge
.. code-block:: bash
conda config --add channels conda-forge
conda install locopy
Installation instructions
A virtual or conda environment is highly recommended
.. code-block:: bash
$ virtualenv locopy
$ source locopy/bin/activate
$ pip install --upgrade setuptools pip
$ pip install locopy
Python Database API Specification 2.0
Rather than using a specific Python DB Driver / Adapter for Postgres (which should supports Amazon
Redshift or Snowflake), locopy prefers to be agnostic. As an end user you can use any Python
Database API Specification 2.0 package.
The following packages have been tested:
psycopg2pg8000snowflake-connector-python
You can use which ever one you prefer by importing the package and passing it
into the constructor input dbapi.
Usage
You need to store your connection parameters in a YAML file (or pass them in directly). The YAML would consist of the following items:
.. code-block:: yaml
# required to connect to redshift
host: my.redshift.cluster.com
port: 5439
database: db
user: userid
password: password
## optional extras for the dbapi connector
sslmode: require
another_option: 123
If you aren't loading data, you don't need to have AWS tokens set up.
The Redshift connection (Redshift) can be used like this:
.. code-block:: python
import pg8000
import locopy
with locopy.Redshift(dbapi=pg8000, config_yaml="config.yml") as redshift:
redshift.execute("SELECT * FROM schema.table")
df = redshift.to_dataframe()
print(df)
If you want to load data to Redshift via S3, the Redshift class inherits from S3:
.. code-block:: python
import pg8000
import locopy
with locopy.Redshift(dbapi=pg8000, config_yaml="config.yml") as redshift:
redshift.execute("SET query_group TO quick")
redshift.execute("CREATE TABLE schema.table (variable VARCHAR(20)) DISTKEY(variable)")
redshift.load_and_copy(
local_file="example/example_data.csv",
s3_bucket="my_s3_bucket",
table_name="schema.table",
delim=",")
redshift.execute("SELECT * FROM schema.table")
res = redshift.cursor.fetchall()
print(res)
If you want to download data from Redshift to a CSV, or read it into Python
.. code-block:: python
my_profile = "some_profile_with_valid_tokens"
with locopy.Redshift(dbapi=pg8000, config_yaml="config.yml", profile=my_profile) as redshift:
##Optionally provide export if you ALSO want the exported data copied to a flat file
redshift.unload_and_copy(
query="SELECT * FROM schema.table",
s3_bucket="my_s3_bucket",
export_path="my_output_destination.csv")
Note on tokens ^^^^^^^^^^^^^^
To load data to S3, you will need to be able to generate AWS tokens, or assume the IAM role on a EC2 instance. There are a few options for doing this, depending on where you're running your script and how you want to handle tokens. Once you have your tokens, they need to be accessible to the AWS command line interface. See http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#config-settings-and-precedence for more information, but you can:
- Populate environment variables
AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY, etc. - Leverage the AWS credentials file. If you have multiple profiles configured
you can either call
locopy.Redshift(profile="my-profile"), or set up an environment variableAWS_DEFAULT_PROFILE. - If you are on a EC2 instance you can assume the credentials associated with the IAM role attached.
Advanced Usage
See the docs <https://capitalone.github.io/locopy/>_ for
more detailed usage instructions and examples including Snowflake.
Contributors
We welcome and appreciate your contributions! Before we can accept any contributions, we ask that you please be sure to
sign the Contributor License Agreement (CLA) <https://cla-assistant.io/capitalone/locopy>_.
This project adheres to the Open Source Code of Conduct <https://developer.capitalone.com/resources/code-of-conduct/>_.
By participating, you are expected to honor this code.
Roadmap
Roadmap details can be found here <https://github.com/capitalone/locopy/blob/develop/ROADMAP.rst>_
Explorer des projets similaires
Asabeneh/30-Days-Of-Python
Le défi de programmation 30 Days of Python est un guide pas à pas pour apprendre le langage de programmation Python en 30 jours. Ce défi peut prendre plus de 100 jours. Avancez à votre rythme. Ces vidéos peuvent aussi vous aider : https://www.youtube.com/channel/UC7PNRuno1rzYPb1xLa4yktw
78,707 étoilesgrafana/grafana
Plateforme ouverte et composable d’observabilité et de visualisation de données. Visualise les métriques, les journaux et les traces issus de plusieurs sources, comme Prometheus, Loki, Elasticsearch, InfluxDB, Postgres et bien d’autres.
77,892 étoilesredis/redis
Pour les développeurs qui créent des applications en temps réel pilotées par les données, Redis est le cache, le serveur de structures de données et le moteur de requêtes documentaires et vectorielles préféré, le plus rapide et le plus riche en fonctionnalités.
77,490 étoilesapache/superset
Apache Superset est une plateforme de visualisation et d'exploration de données.
75,520 étoiles