Skip to main content

Helps Python and Django projects import data exposed by Data Flow into a S3 bucket

Project description

Data Flow S3 Importer

This package helps Python and Django projects import data exposed by Data Flow into an S3 bucket.

Data Flow is a data pipeline service that can be made to write data into S3 buckets for ingestion by client applications.

This package will use boto to connect to the given bucket, find the right location within the bucket and read the list of files in there.

It will then take a single file and process it line by line, expecting a JSON object with an 'object' key containing a single entity on each line:

...
{"object": {...}}
...

It is possible to override the base class for plain python projects, or the subclass for Django projects.

The subclass will process each object into an instance of the given model, which will be saved to the DB.

If the model inherits from the provided IngestedModel, any instances not included in the most recent fetch will be flagged as deleted upstream and won't by default appear in the queryset, although they won't be deleted.

Usage

Make a subclass for each of the record sets you want to import.

Plain python

If you're not using Django, or you want full control over how your models are synced (for example you don't want to use queryset methods to update them) then you should subclass the DataFlowS3Ingest ingester class.

This class provides various hooks for configuration and processing; the config you'll need can be applied in the subclass attributes as follows

from data_flow_s3_import.ingest import DataFlowS3Ingest

class MyIngest(DataFlowS3Ingest):
    export_bucket = "my_bucket_name"
    export_path = "bucket_import_type_prefix"
    export_directory = "ingested_data_prefix/"

    def get_s3_resource(self):
        # this should return a configured and instantiated boto3 S3 resource

You will then want to override process_object and/or the other hooks in the class provided as suits your requirements.

Instantiating the class will run the ingestion automatically.

Standard Django models

If you're using Django and want to have your import process automated, start by making a custom model in your app, extending IngestedModel

from data_flow_s3_import.models import IngestedModel

class MyIngestedModel(IngestedModel):
    ...

You will also want to subclass the DataFlowS3IngestToModel importer, setting the mapping dictionary with the key being the model field name and the value being the imported data column name

from data_flow_s3_import.ingest import DataFlowS3IngestToModel

class MyModelIngest(DataFlowS3IngestToModel):
    model = MyIngestedModel
    mapping = {
        "id": "importedColumns:id",
        "name": "importedColumns:NameField",
    }

And then simply instantiate your class and the ingestion will run automatically, syncing your models with the ingested records

MyModelIngest(s3_resource=boto_s3_instance, bucket_name="my_bucket")

You will also need to configure the S3, bucket and path information as in the plain python implementation.

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

data_flow_s3_import-0.0.2.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

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

data_flow_s3_import-0.0.2-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file data_flow_s3_import-0.0.2.tar.gz.

File metadata

  • Download URL: data_flow_s3_import-0.0.2.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.1 CPython/3.11.6 Darwin/24.4.0

File hashes

Hashes for data_flow_s3_import-0.0.2.tar.gz
Algorithm Hash digest
SHA256 ee598d4b06aa3c1ba5a8904f49d425f1bd75fb51eb7eeaa53b8377f50e646b71
MD5 75a57a7e905a7eb9df2ab676f7305919
BLAKE2b-256 786cc51546694d855c855e99974c0d9d0a153fc44e2604ff95402a64453288ba

See more details on using hashes here.

File details

Details for the file data_flow_s3_import-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for data_flow_s3_import-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 79959d769b8dc7817ef581c24be6e2b6be9e9b5c7f3b65bef4655a7a84c118c4
MD5 22984cea894332b8fd1b567c5c67275e
BLAKE2b-256 e051853bcf6298cb778c2dcf3d6b770a43518471e146ea16207f35c2834b9c8d

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