Skip to main content

Light IO transforms for Postgres read/write in Apache Beam pipelines.

Project description

beam-postgres

Light IO transforms for Postgres read/write in Apache Beam pipelines.

Goal

The project aims to provide highly performant and customizable transforms and is not intended to support many different SQL database engines.

Features

  • ReadFromPostgres and WriteToPostgres transforms
  • Records can be mapped to tuples, dictionaries or dataclasses
  • Writes are in configurable batches

Usage

Printing data from the database table:

import apache_beam as beam
from psycopg.rows import dict_row

from beam_postgres.io import ReadFromPostgres

with beam.Pipeline() as p:
    data = p | "Reading example records from database" >> ReadFromPostgres(
        "host=localhost dbname=examples user=postgres password=postgres",
        "select id, data from source",
        dict_row,
    )
    data | "Writing to stdout" >> beam.Map(print)

Writing data to the database table:

from dataclasses import dataclass

import apache_beam as beam
from apache_beam.options.pipeline_options import PipelineOptions

from beam_postgres.io import WriteToPostgres


@dataclass
class Example:
    data: str


with beam.Pipeline(options=PipelineOptions()) as p:
    data = p | "Reading example records" >> beam.Create(
        [
            Example("example1"),
            Example("example2"),
        ]
    )
    data | "Writing example records to database" >> WriteToPostgres(
        "host=localhost dbname=examples user=postgres password=postgres",
        "insert into sink (data) values (%s)",
    )

See here for more examples.

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

beam-postgres-0.1.0.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

beam_postgres-0.1.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file beam-postgres-0.1.0.tar.gz.

File metadata

  • Download URL: beam-postgres-0.1.0.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.15

File hashes

Hashes for beam-postgres-0.1.0.tar.gz
Algorithm Hash digest
SHA256 57413a66e2dfcb90486d181136b1be9669a8a871c9bd7c771fd98c4c8def0e26
MD5 028b9dfb9aefdbc423eb7b512b9b64d0
BLAKE2b-256 6e3e37a1224dc6cb09f828d994818ade9fc7305408cbb8eaf0f48c9ed2b9ebe6

See more details on using hashes here.

File details

Details for the file beam_postgres-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for beam_postgres-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 534a2a79996ee284922b3783857711d4316e15886ce1368ce4aea0bfbf6703d1
MD5 e4698df80088a1946d927790195c81f1
BLAKE2b-256 36b912f90104f450bfee0e5c4e3e32ae4c2787a62482bd705a13560e4d8cdbdf

See more details on using hashes here.

Supported by

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