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.1.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.

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: coplin_db2-2.1.6.1.tar.gz
  • Upload date:
  • Size: 8.0 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.1.tar.gz
Algorithm Hash digest
SHA256 e1c6fe8483d2e9bdbb402779202e246648b55b8e81d978a49740100fc248d3f0
MD5 a83a67be4635b14256bb375cd494456a
BLAKE2b-256 e8b1f1cca6706ef1faab1efcd62e1e33ce699c11cc12812d807f6c703c03821e

See more details on using hashes here.

Provenance

The following attestation bundles were made for coplin_db2-2.1.6.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: coplin_db2-2.1.6.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 eb118d0fcc6a68984858ad05cea10935931c0665ffcc56e66bfa76e188b7859e
MD5 6a02b65082208ead6fe49b8cf4a58101
BLAKE2b-256 5d491e67c5d7bce2564b8db048c074062fac403f61c1042888b1427fff8e86cf

See more details on using hashes here.

Provenance

The following attestation bundles were made for coplin_db2-2.1.6.1-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