Skip to main content

Um módulo de conveniência para manipulação de bancos de dados IBM DB2 em Python.

Project description

coplin-db2

A biblioteca coplin-db2 é um módulo de conveniência para acessar bancos de dados do tipo IBM DB2, desenvolvido pela Coordenadoria de Planejamento Informacional da UFSM (COPLIN).

Com esta biblioteca, é possível definir um arquivo com credenciais de acesso ao banco de dados, no formato json, que podem ser utilizadas posteriormente:

Arquivo credentials.json:

{
  "user": "nome_de_usuário",
  "password": "sua_senha_aqui",
  "host": "URL_do_host",
  "port": 50000,
  "database": "nome_do_banco"
}

Arquivo db2_schema.sql:

CREATE TABLE USERS_TEST_IBMDB2(
    ID INTEGER NOT NULL PRIMARY KEY,
    NAME VARCHAR(10) NOT NULL,
    AGE INTEGER NOT NULL
);

INSERT INTO USERS_TEST_IBMDB2(ID, NAME, AGE) VALUES (1, 'HENRY', 32);
INSERT INTO USERS_TEST_IBMDB2(ID, NAME, AGE) VALUES (2, 'JOHN', 20);

Arquivo main.py:

import os
from db2 import DB2Connection

# arquivo JSON com credenciais de login para o banco de dados
credentials = 'credentials.json'

with DB2Connection(credentials) as db2_conn:
    db2_conn.create_tables('db2_schema.sql')
    query_str = '''
        SELECT * 
        FROM USERS_TEST_IBMDB2;
     ''' 
    df = db2_conn.query_to_dataframe(query_str)
    
    print(df)
    
    # deleta a tabela
    # db2_conn.modify('''DROP TABLE USERS_TEST_IBMDB2;''', suppress=False)

A saída esperada deve ser:

   ID   NAME  AGE
0   1  HENRY   32
1   2   JOHN   20

Instalação

Para instalar o pacote pelo pip, digite o seguinte comando:

pip install coplin-db2

Documentação

A documentação está disponível em https://coplin-ufsm.github.io/db2

Desenvolvimento

Para instruções de desenvolvimento do pacote, consulte este arquivo.

Contato

Biblioteca desenvolvida originalmente por Henry Cagnini: henry.cagnini@ufsm.br

Caso encontre algum problema no uso, abra um issue no repositório da biblioteca.

Pull requests são bem-vindos!

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

coplin_db2-2.1.6.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

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

coplin_db2-2.1.6-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file coplin_db2-2.1.6.tar.gz.

File metadata

  • Download URL: coplin_db2-2.1.6.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for coplin_db2-2.1.6.tar.gz
Algorithm Hash digest
SHA256 1add40de61f2fe91acf48bad158258cb978c4e1be6cdd88c7b811f919682950c
MD5 b7da41598c53d4fdb4d08ac8e70a2f6d
BLAKE2b-256 2a10f9f594a0a3050f81e31a732a6c78135e092623b4cb9278ae3eb6e82470bb

See more details on using hashes here.

Provenance

The following attestation bundles were made for coplin_db2-2.1.6.tar.gz:

Publisher: python-publish.yml on COPLIN-UFSM/db2

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file coplin_db2-2.1.6-py3-none-any.whl.

File metadata

  • Download URL: coplin_db2-2.1.6-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for coplin_db2-2.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 441255b19d6ff9ea371d0dc12eb947c256688e201f010aec9760cc0a738ad565
MD5 1e6a391dd180558ef7d0e6aba1c05537
BLAKE2b-256 b928d87347af663f571c4254f9dd6f50cd3bf721dd6e3704a8b3b3a56b6596da

See more details on using hashes here.

Provenance

The following attestation bundles were made for coplin_db2-2.1.6-py3-none-any.whl:

Publisher: python-publish.yml on COPLIN-UFSM/db2

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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