Skip to main content

Manipulate data on Amazon S3 using Apache Hadoop filesystem compability

Project description

Data Lake Utility

Package to manipulate data from/into Amazon S3 using partitions compatible with Apache Hadoop filesystem. At this moment, this package was conceived to handle JSON and Parquet formats. That being said, it expects a Pandas DataFrame.

Data will be written into Amazon S3 as a multi-line JSON or Apache Parquet, compressed as GZIP.

Features

Convert list of dictionaries...

[
    {"brand": "Ford","model": "Mustang","year": 1965},
    {"brand": "Pontiac","model": "GTO","year": 1964},
    {"brand": "Lamborghini","model": "Miura","year": 1966}
]

...to multi-line JSON compressed as GZIP

{"brand": "Ford","model": "Mustang","year": 1965}
{"brand": "Pontiac","model": "GTO","year": 1964}
{"brand": "Lamborghini","model": "Miura","year": 1966}

...or to Apache Parquet compressed as GZIP

How to use

This package does not slice data into partitions at the moment. You must handle slicing of data to write into partitions desired.

Check this example below:

from datalake_utils.utils import DataLake
import pandas

data = [
    {
        "brand": "Ford",
        "model": "Mustang",
        "year": 1965
    },
    {
        "brand": "Pontiac",
        "model": "GTO",
        "year": 1964
    },
    {
        "brand": "Lamborghini",
        "model": "Miura",
        "year": 1966
    }
]

datalake = DataLake(
    bucket_name="vehicles",
    schema="motor_vehicles",
    table="cars",
    partitions=[
        {
            "key": "decade",
            "value": "1960s"
        }
    ],
)

datalake.append_to_s3(data=pandas.DataFrame(data), file_format="json")

It will create an object into Amazon S3 with the following structure:

motor_vehicles/
`-- cars/
    `-- decade=1960s/
        `-- 2c0fea6c-444e-11ed-969f-acde48001122.json.gz

To read all files from partition, do:

retrieved_data = datalake.read_from_s3(file_format="json")

retrieved_data is a Pandas DataFrame object. It is not possible to read a specific file using this function.

To convert a Pandas DataFrame into a list of tuples containing a single JSON:

datalake.df_to_tuples(data=retrieved_data)

To delete all files from partition, do:

datalake.delete_from_s3()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

datalake_utils-2.2.1.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

datalake_utils-2.2.1-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file datalake_utils-2.2.1.tar.gz.

File metadata

  • Download URL: datalake_utils-2.2.1.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.13

File hashes

Hashes for datalake_utils-2.2.1.tar.gz
Algorithm Hash digest
SHA256 cd3ead1c81fc44e7a99c1dc6b1a8c84b9e1ec5a8de094d2be295ba9cf1ccc88c
MD5 895539d013ca9d685d288c5ce377e0d4
BLAKE2b-256 0fc1609da310f6fc0fff7954e0b08b0caaf864542cec3446fa2b0f115fea3829

See more details on using hashes here.

File details

Details for the file datalake_utils-2.2.1-py3-none-any.whl.

File metadata

  • Download URL: datalake_utils-2.2.1-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.13

File hashes

Hashes for datalake_utils-2.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ae052b0ea13fe7c013cd2ae08d6aa4eff6921a3126143e13733352739231c14c
MD5 814c1f64045978f9a6f765893720f31b
BLAKE2b-256 bf267659f04cf4367d326fe523997d61cb4e7f563dc8fbfa06e507415245b67b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page