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
,ReadFromPostgres`` and
WriteToPostgres` transforms- Records can be mapped to tuples, dictionaries or dataclasses
- Reads and 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
Release history Release notifications | RSS feed
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.4.0.tar.gz
(10.4 kB
view hashes)
Built Distribution
Close
Hashes for beam_postgres-0.4.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7184d239e3d74ab5a838aa13f5680efd6efad60a57c49c0dc6ea94fa84c17834 |
|
MD5 | a245736e47b1a7c4ac89ddaa604ec593 |
|
BLAKE2b-256 | a6d2e55daf079b4ed67e9913b57b361c90c7952dc92c096021df79b6728773ef |