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.3.tar.gz (8.5 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.3-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: coplin_db2-2.3.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for coplin_db2-2.3.tar.gz
Algorithm Hash digest
SHA256 745e4be2a6e61da72285598a2064fcf140cb2b31be139a050def369119e06b8d
MD5 208d73eee979e9e917e47229b654880e
BLAKE2b-256 52866f8d49a844dcf2cdd8711f582a1f1a44960098edb7ae65e7f10f9c92bdb3

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: coplin_db2-2.3-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for coplin_db2-2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 324c47096c936192524ee5d97812d01697cac87a99ba12a4ea8527aa62b76618
MD5 c964c97e801d93a3282bda31a9c28102
BLAKE2b-256 44a7625f8db36b79331cae9e3233cbd31d548c63bed2460ab464e628b1d34cca

See more details on using hashes here.

Provenance

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