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

  • ReadAllFromPostgres 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 ReadAllFromPostgres

with beam.Pipeline() as p:
    data = p | "Reading example records from database" >> ReadAllFromPostgres(
        "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.2.2.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

beam_postgres-0.2.2-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: beam-postgres-0.2.2.tar.gz
  • Upload date:
  • Size: 9.1 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.2.2.tar.gz
Algorithm Hash digest
SHA256 b7cdce4cf0b58ee0881ced223782611098327b4f34a791f1dfbd33eb05de02ee
MD5 136e62e8cb128e57e02675ebd9e501cd
BLAKE2b-256 5ff1122ec96b50782b970ab167e58c6feb5e91b251cd643e8c73f485144e9177

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for beam_postgres-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3987b4b0c99382ddf791c6cd21d3dbff7fa9564e2adc7bad81bc53750e8b7aa4
MD5 e548222b2a797e4131f703919b410baf
BLAKE2b-256 7514598f59d8e0bf7c12e11544855f2daadfd11df7c9067287a949d84bdeac66

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