deepread-contract 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,41 @@
1
+ # Byte-compiled / optimized
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+
7
+ # Distribution / packaging
8
+ build/
9
+ dist/
10
+ *.egg-info/
11
+ *.egg
12
+ .eggs/
13
+
14
+ # Virtual environments
15
+ .venv/
16
+ venv/
17
+ ENV/
18
+
19
+ # IDE
20
+ .idea/
21
+ .vscode/
22
+ *.swp
23
+ *.swo
24
+
25
+ # OS
26
+ .DS_Store
27
+
28
+ # Testing
29
+ .pytest_cache/
30
+ .coverage
31
+ htmlcov/
32
+
33
+ # Secrets
34
+ .env
35
+ .env.*
36
+ *.env
37
+ secrets.py
38
+
39
+ # PDFs de teste
40
+ tests/*.pdf
41
+ *.pdf
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Monkai
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,291 @@
1
+ Metadata-Version: 2.4
2
+ Name: deepread-contract
3
+ Version: 0.1.0
4
+ Summary: Biblioteca para validação de documentos e contratos brasileiros
5
+ Project-URL: Homepage, https://github.com/BeMonkAI/deepread.contract
6
+ Project-URL: Documentation, https://github.com/BeMonkAI/deepread.contract#readme
7
+ Project-URL: Repository, https://github.com/BeMonkAI/deepread.contract
8
+ Project-URL: Issues, https://github.com/BeMonkAI/deepread.contract/issues
9
+ Author-email: BeMonkAI <contato@bemonk.ai>
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: brasil,cnpj,contract,document,pdf,receita-federal,validation
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: Legal Industry
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.9
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Topic :: Office/Business
24
+ Classifier: Topic :: Text Processing :: General
25
+ Requires-Python: >=3.9
26
+ Requires-Dist: pydantic>=2.0.0
27
+ Requires-Dist: requests>=2.25.0
28
+ Provides-Extra: ai
29
+ Requires-Dist: openai>=1.0.0; extra == 'ai'
30
+ Provides-Extra: dev
31
+ Requires-Dist: black>=23.0.0; extra == 'dev'
32
+ Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
33
+ Requires-Dist: pytest>=7.0.0; extra == 'dev'
34
+ Requires-Dist: ruff>=0.1.0; extra == 'dev'
35
+ Description-Content-Type: text/markdown
36
+
37
+ # DeepRead Contract 📄
38
+
39
+ [![PyPI version](https://badge.fury.io/py/deepread-contract.svg)](https://pypi.org/project/deepread-contract/)
40
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
41
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
42
+
43
+ Biblioteca Python para **validação de documentos e contratos brasileiros**.
44
+
45
+ Consulta dados de empresas na **Receita Federal** e valida:
46
+ - ✅ CNPJ (situação cadastral)
47
+ - ✅ Razão Social
48
+ - ✅ Endereços
49
+ - ✅ Poder de assinatura (QSA)
50
+
51
+ ## Instalação
52
+
53
+ ```bash
54
+ pip install deepread-contract
55
+ ```
56
+
57
+ ## Uso Rápido
58
+
59
+ ### Consultar CNPJ
60
+
61
+ ```python
62
+ from deepread_contract import consultar_cnpj, validar_cnpj
63
+
64
+ # Validar formato
65
+ if validar_cnpj("33.000.167/0001-01"):
66
+ # Consultar na Receita Federal
67
+ dados = consultar_cnpj("33.000.167/0001-01")
68
+
69
+ print(dados["razao_social"]) # PETROLEO BRASILEIRO S A PETROBRAS
70
+ print(dados["situacao"]) # ATIVA
71
+ print(dados["socios"]) # Lista de sócios/administradores
72
+ ```
73
+
74
+ ### Buscar Empresa por Nome
75
+
76
+ ```python
77
+ from deepread_contract import buscar_cnpj_por_nome
78
+
79
+ dados = buscar_cnpj_por_nome("Petrobras")
80
+ print(dados["cnpj"]) # 33.000.167/0001-01
81
+ ```
82
+
83
+ ### Validar Documento
84
+
85
+ ```python
86
+ from deepread_contract import validar_documento_contrato
87
+
88
+ texto = """
89
+ CONTRATO DE PRESTAÇÃO DE SERVIÇOS
90
+ CONTRATANTE: Empresa XYZ, inscrita no CNPJ...
91
+ CLÁUSULA PRIMEIRA - OBJETO
92
+ """
93
+
94
+ eh_contrato, qtd_keywords, keywords = validar_documento_contrato(texto)
95
+ print(f"É contrato: {eh_contrato}") # True
96
+ ```
97
+
98
+ ### Formatar CNPJ
99
+
100
+ ```python
101
+ from deepread_contract import formatar_cnpj, limpar_cnpj
102
+
103
+ formatar_cnpj("33000167000101") # "33.000.167/0001-01"
104
+ limpar_cnpj("33.000.167/0001-01") # "33000167000101"
105
+ ```
106
+
107
+ ## Verificação de Contratos (com DeepRead)
108
+
109
+ ### OpenAI
110
+
111
+ ```python
112
+ from deepread_contract import ContractChecker
113
+
114
+ checker = ContractChecker(openai_api_key="sk-...")
115
+ resultado = checker.verificar("contrato.pdf")
116
+
117
+ print(resultado["resultado_final"]) # APROVADO, REPROVADO, PENDENTE
118
+ print(resultado["campos_aprovados"])
119
+ print(resultado["campos_reprovados"])
120
+ ```
121
+
122
+ ### Azure OpenAI
123
+
124
+ ```python
125
+ from deepread_contract import ContractChecker
126
+
127
+ checker = ContractChecker(
128
+ provider="azure",
129
+ azure_api_key="sua-chave-azure",
130
+ azure_endpoint="https://seu-recurso.openai.azure.com",
131
+ azure_deployment="gpt-4o",
132
+ azure_api_version="2024-02-15-preview"
133
+ )
134
+
135
+ resultado = checker.verificar("contrato.pdf")
136
+ ```
137
+
138
+ ### Via Variáveis de Ambiente
139
+
140
+ ```bash
141
+ # OpenAI
142
+ export OPENAI_API_KEY=sk-...
143
+
144
+ # Azure
145
+ export OPENAI_PROVIDER=azure
146
+ export AZURE_API_KEY=sua-chave-azure
147
+ export AZURE_API_ENDPOINT=https://seu-recurso.openai.azure.com
148
+ export AZURE_DEPLOYMENT_NAME=gpt-4o
149
+ export AZURE_API_VERSION=2024-02-15-preview
150
+ ```
151
+
152
+ ```python
153
+ # Detecta automaticamente do ambiente
154
+ checker = ContractChecker()
155
+ print(checker.provider) # "openai" ou "azure"
156
+ ```
157
+
158
+ ## Autenticação
159
+
160
+ ### DeepReadAuth
161
+
162
+ ```python
163
+ from deepread_contract import DeepReadAuth
164
+
165
+ # OpenAI
166
+ auth = DeepReadAuth(openai_api_key="sk-...")
167
+
168
+ # Azure
169
+ auth = DeepReadAuth(
170
+ provider="azure",
171
+ azure_api_key="sua-chave",
172
+ azure_endpoint="https://seu-recurso.openai.azure.com",
173
+ azure_deployment="gpt-4o"
174
+ )
175
+
176
+ # Verificar configuração
177
+ print(auth.provider) # "openai" ou "azure"
178
+ print(auth.has_api_key) # True/False
179
+ print(auth.is_deepread_available) # True/False
180
+
181
+ # Obter token
182
+ token = auth.get_token()
183
+ ```
184
+
185
+ ### AuthenticatedClient
186
+
187
+ ```python
188
+ from deepread_contract import AuthenticatedClient
189
+
190
+ client = AuthenticatedClient(
191
+ provider="azure",
192
+ azure_api_key="...",
193
+ azure_endpoint="...",
194
+ azure_deployment="gpt-4o"
195
+ )
196
+
197
+ if client.is_ready:
198
+ dr = client.get_deepread_client()
199
+ resultado = dr.process("documento.pdf")
200
+ ```
201
+
202
+ ## CLI
203
+
204
+ ```bash
205
+ # Consultar CNPJ
206
+ deepread-contract cnpj 33.000.167/0001-01
207
+
208
+ # Buscar por nome
209
+ deepread-contract buscar "Petrobras"
210
+
211
+ # Verificar contrato
212
+ deepread-contract verificar contrato.pdf
213
+
214
+ # Saída em JSON
215
+ deepread-contract cnpj 33.000.167/0001-01 --json
216
+ ```
217
+
218
+ ## Estrutura de Resposta CNPJ
219
+
220
+ ```python
221
+ {
222
+ "cnpj": "33.000.167/0001-01",
223
+ "razao_social": "PETROLEO BRASILEIRO S A PETROBRAS",
224
+ "nome_fantasia": "PETROBRAS",
225
+ "situacao": "ATIVA",
226
+ "data_abertura": "1966-09-28",
227
+ "natureza_juridica": "Sociedade de Economia Mista",
228
+ "capital_social": 205431960490.0,
229
+ "endereco": {
230
+ "logradouro": "AVENIDA REPUBLICA DO CHILE",
231
+ "numero": "65",
232
+ "bairro": "CENTRO",
233
+ "cidade": "RIO DE JANEIRO",
234
+ "uf": "RJ",
235
+ "cep": "20031912"
236
+ },
237
+ "socios": [
238
+ {"nome": "JOAO SILVA", "qualificacao": "Diretor"},
239
+ ...
240
+ ]
241
+ }
242
+ ```
243
+
244
+ ## Estrutura de Resposta Verificação
245
+
246
+ ```python
247
+ {
248
+ "resultado_final": "APROVADO", # APROVADO, REPROVADO, PENDENTE
249
+ "justificativa": "Todos os campos aprovados",
250
+ "campos_aprovados": ["CNPJ - Empresa X", "Situação - Empresa X", ...],
251
+ "campos_reprovados": [],
252
+ "campos_pendentes": [],
253
+ "empresas": [...],
254
+ "assinaturas": [...],
255
+ "metricas": {
256
+ "tokens": 5000,
257
+ "custo_usd": 0.025,
258
+ "tempo_segundos": 12.5
259
+ }
260
+ }
261
+ ```
262
+
263
+ ## Exemplos
264
+
265
+ Veja a pasta [`examples/`](examples/) para exemplos completos:
266
+
267
+ - `exemplo_cnpj.py` - Consulta de CNPJ
268
+ - `exemplo_validacao_documento.py` - Validação de documento
269
+ - `exemplo_verificar_contrato.py` - Verificação completa
270
+ - `exemplo_cli.sh` - Comandos CLI
271
+
272
+ ## Dependências
273
+
274
+ ### Obrigatórias
275
+ - `requests` - Requisições HTTP
276
+ - `pydantic` - Validação de dados
277
+
278
+ ### Opcionais
279
+ - `openai` - Para usar com OpenAI/Azure
280
+
281
+ ## Licença
282
+
283
+ MIT License - veja [LICENSE](LICENSE) para detalhes.
284
+
285
+ ## Contribuição
286
+
287
+ Contribuições são bem-vindas! Abra uma issue ou pull request.
288
+
289
+ ---
290
+
291
+ Desenvolvido por [BeMonkAI](https://github.com/BeMonkAI)
@@ -0,0 +1,255 @@
1
+ # DeepRead Contract 📄
2
+
3
+ [![PyPI version](https://badge.fury.io/py/deepread-contract.svg)](https://pypi.org/project/deepread-contract/)
4
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+
7
+ Biblioteca Python para **validação de documentos e contratos brasileiros**.
8
+
9
+ Consulta dados de empresas na **Receita Federal** e valida:
10
+ - ✅ CNPJ (situação cadastral)
11
+ - ✅ Razão Social
12
+ - ✅ Endereços
13
+ - ✅ Poder de assinatura (QSA)
14
+
15
+ ## Instalação
16
+
17
+ ```bash
18
+ pip install deepread-contract
19
+ ```
20
+
21
+ ## Uso Rápido
22
+
23
+ ### Consultar CNPJ
24
+
25
+ ```python
26
+ from deepread_contract import consultar_cnpj, validar_cnpj
27
+
28
+ # Validar formato
29
+ if validar_cnpj("33.000.167/0001-01"):
30
+ # Consultar na Receita Federal
31
+ dados = consultar_cnpj("33.000.167/0001-01")
32
+
33
+ print(dados["razao_social"]) # PETROLEO BRASILEIRO S A PETROBRAS
34
+ print(dados["situacao"]) # ATIVA
35
+ print(dados["socios"]) # Lista de sócios/administradores
36
+ ```
37
+
38
+ ### Buscar Empresa por Nome
39
+
40
+ ```python
41
+ from deepread_contract import buscar_cnpj_por_nome
42
+
43
+ dados = buscar_cnpj_por_nome("Petrobras")
44
+ print(dados["cnpj"]) # 33.000.167/0001-01
45
+ ```
46
+
47
+ ### Validar Documento
48
+
49
+ ```python
50
+ from deepread_contract import validar_documento_contrato
51
+
52
+ texto = """
53
+ CONTRATO DE PRESTAÇÃO DE SERVIÇOS
54
+ CONTRATANTE: Empresa XYZ, inscrita no CNPJ...
55
+ CLÁUSULA PRIMEIRA - OBJETO
56
+ """
57
+
58
+ eh_contrato, qtd_keywords, keywords = validar_documento_contrato(texto)
59
+ print(f"É contrato: {eh_contrato}") # True
60
+ ```
61
+
62
+ ### Formatar CNPJ
63
+
64
+ ```python
65
+ from deepread_contract import formatar_cnpj, limpar_cnpj
66
+
67
+ formatar_cnpj("33000167000101") # "33.000.167/0001-01"
68
+ limpar_cnpj("33.000.167/0001-01") # "33000167000101"
69
+ ```
70
+
71
+ ## Verificação de Contratos (com DeepRead)
72
+
73
+ ### OpenAI
74
+
75
+ ```python
76
+ from deepread_contract import ContractChecker
77
+
78
+ checker = ContractChecker(openai_api_key="sk-...")
79
+ resultado = checker.verificar("contrato.pdf")
80
+
81
+ print(resultado["resultado_final"]) # APROVADO, REPROVADO, PENDENTE
82
+ print(resultado["campos_aprovados"])
83
+ print(resultado["campos_reprovados"])
84
+ ```
85
+
86
+ ### Azure OpenAI
87
+
88
+ ```python
89
+ from deepread_contract import ContractChecker
90
+
91
+ checker = ContractChecker(
92
+ provider="azure",
93
+ azure_api_key="sua-chave-azure",
94
+ azure_endpoint="https://seu-recurso.openai.azure.com",
95
+ azure_deployment="gpt-4o",
96
+ azure_api_version="2024-02-15-preview"
97
+ )
98
+
99
+ resultado = checker.verificar("contrato.pdf")
100
+ ```
101
+
102
+ ### Via Variáveis de Ambiente
103
+
104
+ ```bash
105
+ # OpenAI
106
+ export OPENAI_API_KEY=sk-...
107
+
108
+ # Azure
109
+ export OPENAI_PROVIDER=azure
110
+ export AZURE_API_KEY=sua-chave-azure
111
+ export AZURE_API_ENDPOINT=https://seu-recurso.openai.azure.com
112
+ export AZURE_DEPLOYMENT_NAME=gpt-4o
113
+ export AZURE_API_VERSION=2024-02-15-preview
114
+ ```
115
+
116
+ ```python
117
+ # Detecta automaticamente do ambiente
118
+ checker = ContractChecker()
119
+ print(checker.provider) # "openai" ou "azure"
120
+ ```
121
+
122
+ ## Autenticação
123
+
124
+ ### DeepReadAuth
125
+
126
+ ```python
127
+ from deepread_contract import DeepReadAuth
128
+
129
+ # OpenAI
130
+ auth = DeepReadAuth(openai_api_key="sk-...")
131
+
132
+ # Azure
133
+ auth = DeepReadAuth(
134
+ provider="azure",
135
+ azure_api_key="sua-chave",
136
+ azure_endpoint="https://seu-recurso.openai.azure.com",
137
+ azure_deployment="gpt-4o"
138
+ )
139
+
140
+ # Verificar configuração
141
+ print(auth.provider) # "openai" ou "azure"
142
+ print(auth.has_api_key) # True/False
143
+ print(auth.is_deepread_available) # True/False
144
+
145
+ # Obter token
146
+ token = auth.get_token()
147
+ ```
148
+
149
+ ### AuthenticatedClient
150
+
151
+ ```python
152
+ from deepread_contract import AuthenticatedClient
153
+
154
+ client = AuthenticatedClient(
155
+ provider="azure",
156
+ azure_api_key="...",
157
+ azure_endpoint="...",
158
+ azure_deployment="gpt-4o"
159
+ )
160
+
161
+ if client.is_ready:
162
+ dr = client.get_deepread_client()
163
+ resultado = dr.process("documento.pdf")
164
+ ```
165
+
166
+ ## CLI
167
+
168
+ ```bash
169
+ # Consultar CNPJ
170
+ deepread-contract cnpj 33.000.167/0001-01
171
+
172
+ # Buscar por nome
173
+ deepread-contract buscar "Petrobras"
174
+
175
+ # Verificar contrato
176
+ deepread-contract verificar contrato.pdf
177
+
178
+ # Saída em JSON
179
+ deepread-contract cnpj 33.000.167/0001-01 --json
180
+ ```
181
+
182
+ ## Estrutura de Resposta CNPJ
183
+
184
+ ```python
185
+ {
186
+ "cnpj": "33.000.167/0001-01",
187
+ "razao_social": "PETROLEO BRASILEIRO S A PETROBRAS",
188
+ "nome_fantasia": "PETROBRAS",
189
+ "situacao": "ATIVA",
190
+ "data_abertura": "1966-09-28",
191
+ "natureza_juridica": "Sociedade de Economia Mista",
192
+ "capital_social": 205431960490.0,
193
+ "endereco": {
194
+ "logradouro": "AVENIDA REPUBLICA DO CHILE",
195
+ "numero": "65",
196
+ "bairro": "CENTRO",
197
+ "cidade": "RIO DE JANEIRO",
198
+ "uf": "RJ",
199
+ "cep": "20031912"
200
+ },
201
+ "socios": [
202
+ {"nome": "JOAO SILVA", "qualificacao": "Diretor"},
203
+ ...
204
+ ]
205
+ }
206
+ ```
207
+
208
+ ## Estrutura de Resposta Verificação
209
+
210
+ ```python
211
+ {
212
+ "resultado_final": "APROVADO", # APROVADO, REPROVADO, PENDENTE
213
+ "justificativa": "Todos os campos aprovados",
214
+ "campos_aprovados": ["CNPJ - Empresa X", "Situação - Empresa X", ...],
215
+ "campos_reprovados": [],
216
+ "campos_pendentes": [],
217
+ "empresas": [...],
218
+ "assinaturas": [...],
219
+ "metricas": {
220
+ "tokens": 5000,
221
+ "custo_usd": 0.025,
222
+ "tempo_segundos": 12.5
223
+ }
224
+ }
225
+ ```
226
+
227
+ ## Exemplos
228
+
229
+ Veja a pasta [`examples/`](examples/) para exemplos completos:
230
+
231
+ - `exemplo_cnpj.py` - Consulta de CNPJ
232
+ - `exemplo_validacao_documento.py` - Validação de documento
233
+ - `exemplo_verificar_contrato.py` - Verificação completa
234
+ - `exemplo_cli.sh` - Comandos CLI
235
+
236
+ ## Dependências
237
+
238
+ ### Obrigatórias
239
+ - `requests` - Requisições HTTP
240
+ - `pydantic` - Validação de dados
241
+
242
+ ### Opcionais
243
+ - `openai` - Para usar com OpenAI/Azure
244
+
245
+ ## Licença
246
+
247
+ MIT License - veja [LICENSE](LICENSE) para detalhes.
248
+
249
+ ## Contribuição
250
+
251
+ Contribuições são bem-vindas! Abra uma issue ou pull request.
252
+
253
+ ---
254
+
255
+ Desenvolvido por [BeMonkAI](https://github.com/BeMonkAI)