Feat/search#2
Merged
Merged
Conversation
Endpoint nao documentado oficialmente (interno do portal): GET https://pncp.gov.br/api/search/ Parametros: q, tipos_documento (obrigatorios) pagina, tam_pagina, ordenacao, status, uf, municipio, modalidade_licitacao (opcionais) Modelo SearchResult com ~30 campos mapeados (orgao, valores, datas, modalidade, situacao, localizacao, etc.) search_all() com paginacao automatica via Page[T]. 58 testes, 91% cobertura, mypy strict.
- Nova secao 'Busca no catalogo' com exemplos - Advertência explicita: API nao documentada oficialmente - Tabela de parametros da search - Modelo SearchResult na secao de modelos - Referencia da API atualizada com search - 58 testes, 91%, mypy strict
PrecosResource (API de integracao, nao documentada): get_items(orgao, ano, compra) -> list[ItemCompra] get_resultados(orgao, ano, compra, item) -> list[ResultadoItem] buscar_precos(q, ...) -> AsyncIterator[dict] (pipeline completo) Modelos: ItemCompra (numero_item, descricao, quantidade, valor, situacao) ResultadoItem (fornecedor, cnpj, valor_homologado, data) Documentacao: Secao 'Precos homologados' no README com exemplos Tabelas ItemCompra e ResultadoItem nos modelos Referencia da API atualizada 63 testes, 86% coverage, mypy strict (13 fontes)
search_all() e buscar_precos() agora aceitam prefetch=N (padrao 1) — a proxima pagina de busca comeca a baixar em background enquanto a pagina atual e processada. 63 testes, 85% coverage, mypy strict.
SearchResource:
search() → query() (mais intuitivo)
search_all() → query_all()
SearchResult.get_resultados():
Metodo lazy que faz fetch dos precos homologados de cada item.
O SearchResource injeta o HttpClient no objeto ao construi-lo.
Cada SearchResult pode buscar seus resultados de forma independente.
Exemplo:
page = await client.search.query("dipirona", ...)
for item in page.data:
resultados = await item.get_resultados()
print(r.fornecedor_nome, r.valor_unitario_homologado)
63 testes, 83% coverage, mypy strict.
testes novos: test_query_all_prefetch_single_page test_resultado_lazy_fetch (pipeline search → itens → precos) test_resultado_sem_resultado (tem_resultado=false) test_resultado_item_url_invalido test_search_result_repr test_buscar_precos_pipeline (ciclo completo) docstrings em minusculo em todos os metodos publicos. injecao do httpx.AsyncClient no searchresult em vez do httpclient wrapper para evitar duplicacao de base_url no fetch lazy de get_resultados(). 69 testes, 91% coverage, mypy strict (13 fontes).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request adds support for non-official PNCP APIs to fetch full-text search results and homologated prices (preços homologados), along with their corresponding models, resources, and documentation. It enables advanced queries over the PNCP catalogue and allows users to retrieve real prices paid by the public administration, including supplier details. The changes include new client resources, data models, and comprehensive documentation and usage examples.
New resources and client integration:
SearchResourceandPrecosResourceto thePNCPClient, enabling access to the/api/search/(catalogue search) and/api/pncp/v1/orgaos/.../itens(homologated prices) endpoints. These resources are now available asclient.searchandclient.precos. [1] [2] [3]Data models for new endpoints:
SearchResult,ItemCompra, andResultadoItemmodels inmodels.pyto represent search results, purchase items, and homologated price results, respectively. These models handle the schemas returned by the new endpoints and provide helper methods for lazy fetching of related data.Documentation and usage examples:
README.mdwith detailed documentation and code samples for catalogue search and homologated prices, including parameter descriptions, usage scenarios, and a complete pipeline example (search → items → prices).Pipeline for price research:
buscar_precosmethod inPrecosResource, which orchestrates the complete workflow: searching the catalogue, retrieving items, and fetching homologated prices, with support for pagination and prefetching.These changes significantly enhance the package's capabilities for market research, price monitoring, and public procurement analysis using data not officially documented by the PNCP.