Skip to main content

3s-rnds-client

3s-rnds-client e uma biblioteca Python assincrona para integracao com a RNDS em aplicacoes Django.

Instalacao

pip install 3s-rnds-client

Visao geral

O cliente concentra a infraestrutura comum de:

  • autenticacao CERT e API
  • cache de token RNDS usando o cache configurado do Django
  • transporte HTTP assincrono com httpx
  • retry automatico em falhas transientes
  • organizacao por capacidades de dominio

Uso rapido

from rnds_client import RndsClient


async def buscar_paciente(identificador: str):
    async with await RndsClient.create() as client:
        return await client.pacientes.buscar_pessoa(identificador)

Modo debug

Para diagnosticar problemas de autenticacao e de consumo da API da RNDS, use buscar_pessoa_debug. O metodo imprime no terminal do servidor o passo a passo do processo, incluindo:

  • variaveis e configuracoes relevantes do fluxo
  • identificador normalizado e URL final da busca
  • leitura do cache de token
  • autenticacao API ou CERT
  • headers enviados
  • status e corpo das respostas HTTP
  • retries e payload final formatado

Exemplo de uso:

from rnds_client import RndsClient


async def buscar_paciente_debug(identificador: str):
    async with await RndsClient.create() as client:
        return await client.pacientes.buscar_pessoa_debug(identificador)

Por padrao, buscar_pessoa_debug usa force_refresh_token=True para forcar a autenticacao e exibir o fluxo completo. Se quiser reproduzir o comportamento padrao da biblioteca tentando reutilizar o token em cache, passe force_refresh_token=False.

from rnds_client import RndsClient


async def buscar_paciente_debug_com_cache(identificador: str):
    async with await RndsClient.create() as client:
        return await client.pacientes.buscar_pessoa_debug(
            identificador,
            force_refresh_token=False,
        )

Os logs do modo debug mascaram parcialmente tokens e senha antes de exibi-los.

Configuracao no Django

O pacote usa o cache padrao do Django para armazenar o token RNDS. Antes de usar o client, garanta que o projeto tenha CACHES configurado.

Exemplo de variaveis de ambiente:

RNDS_API_URL=https://rn-ehr-services.saude.gov.br/api/
RNDS_AUTH_TOKEN_URL=https://ehr-auth.saude.gov.br/api/
RNDS_CNS_GESTOR=

Para compatibilidade com configuracoes legadas, a biblioteca tambem aceita CNS_SEC_SAUDE.

Modo CERT

RNDS_AUTH_METHOD=CERT
RNDS_CERT=/caminho/para/cert.pem
RNDS_KEY=/caminho/para/key.pem

Modo API

RNDS_AUTH_METHOD=API
RNDS_AUTH_LOGIN_URL=https://api-intermediaria.exemplo/login
RNDS_AUTH_TOKEN_URL=https://api-intermediaria.exemplo/token
RNDS_USER=usuario
RNDS_PASSWORD=senha

Se RNDS_AUTH_METHOD nao for informado, o pacote escolhe API quando houver RNDS_USER ou RNDS_PASSWORD; caso contrario, usa CERT.

API publica

O ponto de entrada principal continua sendo RndsClient, com capacidades expostas por dominio:

  • client.pacientes
  • client.estabelecimentos
  • client.rira

Metodos de pacientes:

  • client.pacientes.buscar_pessoa(identificador)
  • client.pacientes.buscar_pessoa_debug(identificador, force_refresh_token=True)

Uso explicito da infraestrutura base:

from httpx import AsyncClient

from rnds_client.base_client import RndsBaseClient
from rnds_client.client import RndsClient
from rnds_client.settings import RndsSettings


async def criar_client_manual():
    settings = RndsSettings.from_environment()
    http_client = AsyncClient(timeout=120.0)
    base_client = RndsBaseClient(settings=settings, http_client=http_client)
    return RndsClient(base_client=base_client)

Clientes HTTP injetados manualmente mantem a configuracao definida pelo consumidor. O cliente criado por RndsClient.create() usa 120 segundos para conexao, leitura, escrita e espera por conexao disponivel.

Tratamento de erros

As excecoes proprias do pacote sao:

  • RndsConfigurationError
  • RndsAuthenticationError

Chamadas HTTP tambem podem propagar erros do httpx.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

3s_rnds_client-0.1.5.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

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

3s_rnds_client-0.1.5-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

Details for the file 3s_rnds_client-0.1.5.tar.gz.

File metadata

  • Download URL: 3s_rnds_client-0.1.5.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for 3s_rnds_client-0.1.5.tar.gz
Algorithm Hash digest
SHA256 4903e84cad5efe5f21433b4d0fdc4a83f7d536655619a2ace0e804f85428c167
MD5 f13f0b2f16760211d9ce639e5fd94fd5
BLAKE2b-256 88e310f49dc1e76d4b5174ced11839d7e94c8f7ca40ec5a44b986846f1663146

See more details on using hashes here.

Provenance

The following attestation bundles were made for 3s_rnds_client-0.1.5.tar.gz:

Publisher: publish.yml on 3S-Saude/3s-rnds-client

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

File details

Details for the file 3s_rnds_client-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: 3s_rnds_client-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 15.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for 3s_rnds_client-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 fa44e12afe04904c91187a4c7dec95f6d24906ff94695e994317ef4bf93a60a8
MD5 c3e5005e45dd79f5867b35d93d0f7356
BLAKE2b-256 ed8344eca7eb84376aa031cd24b9b149ab8ad17fb25e4a3df568f3774479cd38

See more details on using hashes here.

Provenance

The following attestation bundles were made for 3s_rnds_client-0.1.5-py3-none-any.whl:

Publisher: publish.yml on 3S-Saude/3s-rnds-client

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

Release history Release notifications | RSS feed

0.3.1

2 files

0.3.0

2 files

0.2.0

2 files

This release

0.1.5 This release

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page