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

Uploaded Source

Built Distribution

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

loaddata-0.1.1-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: loaddata-0.1.1.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.16

File hashes

Hashes for loaddata-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0e71c9bb6170520e1d6edaab5d9da3cff1420414434ca887b726e32d86d751b8
MD5 fde8ce06e3c701895405a4d8902a3bfd
BLAKE2b-256 a7a4c4be7c9d4e576da0997468b948c9eed2bb00f8607316acbdda8b2bd9621d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: loaddata-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.16

File hashes

Hashes for loaddata-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 18095776df2374303aca42c3eeea09bfe8ff7d818931d762875470d8a1e22ab9
MD5 fa62cfcbf15345976204ebb0f8909b89
BLAKE2b-256 82d34e6adbe3254f918309959ac636950806b7350915d9a61be97b1fd5a8f933

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