Skip to main content

Incremental load to database

Project description

📦 LoadData & DataContractValidator

Este módulo proporciona utilidades para:

  • Carga de datos en PostgreSQL
  • Generación de identificadores únicos
  • Validación de contratos de datos
  • Manejo de fechas

🧱 Clase: LoadData

Clase principal para gestionar la carga de datos en base de datos PostgreSQL.

🔌 enginepsql()

Crea y devuelve un engine de conexión a PostgreSQL usando variables de entorno:

  • USUARIO
  • PASSWORD
  • HOSTNAME
  • PORT
  • DATABASE

🧹 truncate_table(schema, table)

Trunca una tabla sin eliminar su estructura:

  • Desactiva triggers (FKs)
  • Ejecuta TRUNCATE
  • Reactiva triggers

🆔 unique_id_()

Genera un identificador único (unique_id) para cada fila del DataFrame:

  • Usa columnas definidas en uid_cols
  • Limpia strings (lowercase, sin acentos ni caracteres especiales)
  • Genera hash SHA256 → entero int64

📥 load_all_data(...)

Carga datos en PostgreSQL.

Parámetros:

  • input_table: DataFrame a cargar
  • output_table: schema.table
  • uid_cols: columnas para generar ID único
  • uid_need: columna ya existente como ID
  • truncate: si True, borra la tabla antes

Comportamiento:

  • 🔁 Carga incremental (default):

    • Genera unique_id
    • Convierte datos a polars
    • Realiza anti-join para evitar duplicados
  • 🧨 Carga completa (truncate=True):

    • Trunca tabla
    • Inserta todos los datos
  • 🆕 Si la tabla no existe:

    • La crea automáticamente

📊 reportar_datos_aniadidos()

Imprime en consola el número de filas insertadas:

{"datos_aniadidos": X}

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

loaddata-1.1.4.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

loaddata-1.1.4-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file loaddata-1.1.4.tar.gz.

File metadata

  • Download URL: loaddata-1.1.4.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for loaddata-1.1.4.tar.gz
Algorithm Hash digest
SHA256 f3c99dafad021c5ef24956f1b604a47d6f6b73ca786f6926d56969ed8a0c152a
MD5 19b653ce5e11392349f0610ff3808899
BLAKE2b-256 162e9a5f6de3154343c985315018d577bddcf4699f89e73d439e1d3d4e22864d

See more details on using hashes here.

File details

Details for the file loaddata-1.1.4-py3-none-any.whl.

File metadata

  • Download URL: loaddata-1.1.4-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for loaddata-1.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 286609b1cbb372519f53c1a41550f08da94243246d9f3cf49bb12b9ed3c680a8
MD5 94b1e9033a7df3484bc5f54398128360
BLAKE2b-256 810f8edaed728be724385e9c36f3eabd176c09a35699faf00a14ae25fca69281

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page