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.3.0.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

beam_postgres-0.3.0-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: beam-postgres-0.3.0.tar.gz
  • Upload date:
  • Size: 9.2 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.3.0.tar.gz
Algorithm Hash digest
SHA256 2a22765f614c7ff507b02a9cfd7056ea33c2e8e58ad13710a52bb07ddae97780
MD5 7a6273e3f7bab9ff6cef1dd5950c3796
BLAKE2b-256 7399ca05b16f55d49738549d99a4391edbedb7b7ac2993026eab6ec0d44bce44

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for beam_postgres-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bb4fe6f3625604f6a9f012edd460156511432ef0e476b6b62a6c60c932cf82c0
MD5 d773113bfd9199344289943802a66761
BLAKE2b-256 050344260aaacbbe6a0de5c6b66252000d1b798b6757b6a3a0781bb1fe53eceb

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