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
andWriteToPostgres
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
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.3.1.tar.gz
(9.3 kB
view details)
Built Distribution
File details
Details for the file beam-postgres-0.3.1.tar.gz
.
File metadata
- Download URL: beam-postgres-0.3.1.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5809eb8e45fd13505f86d5f7657e6668d3e62d90a3b7d037da68d0017f1c836b |
|
MD5 | b48e7b2c61b9d67ceb8032b66a01bd55 |
|
BLAKE2b-256 | 6830f7a4b4411efd63e2b3ddf10bf37f867d63626eb377766738c547911b2865 |
File details
Details for the file beam_postgres-0.3.1-py3-none-any.whl
.
File metadata
- Download URL: beam_postgres-0.3.1-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a57ff5f160a62d70593db85c86883aed3e57ac8f087f68359b5e45339fbe62cc |
|
MD5 | 051f432672eb70f7f6e30b0b76a37376 |
|
BLAKE2b-256 | d9f4f6ee9ed0195685a33b4dccc396d5996447335e04a27cf02ddd40c3932a19 |