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`` andWriteToPostgres` 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 (%(data)s)",
)
See here for more examples.
Reading in batches
There may be situations when you have so much data that it will not fit into the memory - then you want to read your table data in batches. You can see an example code here (the code reads records in a batches of 1).
Metadata
Release files for beam-postgres 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| beam_postgres-0.5.0.tar.gz | 10.5 kB | Without provenance | Details for beam_postgres-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| beam_postgres-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for beam_postgres-0.5.0-py3-none-any.whl |
Total release size: 21.1 kB
Release files / beam_postgres-0.5.0.tar.gz
| Download URL | beam_postgres-0.5.0.tar.gz |
|---|---|
| Size | 10.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d8172b39a3670046864ba1fd7ff10e18c232dc3816054a5ec22c85e23a9e01e1
|
|
BLAKE2b-256 checksum How to use checksums |
4f191527716ebffe14a84b55e90c50a4980103623d02489a1d3eca082de2c188
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.10.12
|
Release files / beam_postgres-0.5.0-py3-none-any.whl
| Download URL | beam_postgres-0.5.0-py3-none-any.whl |
|---|---|
| Size | 10.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9d7a17a6b3b283ce5a2b5d5ec4c2f779b0bdd9ab8961299fb483dd67985fc36f
|
|
BLAKE2b-256 checksum How to use checksums |
017858b3f2add8c7a39f9dcedc4963a40b950541e3089dbd25e4c669eff8bc77
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.10.12
|
Security for beam-postgres 0.5.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.