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

Uploaded Source

Built Distribution

beam_postgres-0.2.1-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: beam-postgres-0.2.1.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.1.tar.gz
Algorithm Hash digest
SHA256 f96b2b59980ec87f52703a1a37625015f1cb4a2e1dd4daff9c596f23029b9760
MD5 24f9d85861f24a7d9121a6ee618f6d16
BLAKE2b-256 ece0efe273280d56a111d978e3423bf7a6bb65ef4ed01bc25a87078599700610

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for beam_postgres-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 478f26193c37fa88fe0a3fa020df2b343c256e1712a081df0a4ffdc26b56f834
MD5 6ea855490fb75a2ea6d2d1e2b97bb206
BLAKE2b-256 75dc6432520850252a4fa29f2121961ad59624f90516aa268af44efd3f2383e4

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