sienge-python 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.
- sienge_python-0.1.0/.github/workflows/ci.yml +55 -0
- sienge_python-0.1.0/.gitignore +15 -0
- sienge_python-0.1.0/LICENSE +21 -0
- sienge_python-0.1.0/PKG-INFO +208 -0
- sienge_python-0.1.0/README.md +177 -0
- sienge_python-0.1.0/assets/logo-conin.png +0 -0
- sienge_python-0.1.0/examples/consultar_obra.py +50 -0
- sienge_python-0.1.0/examples/pedido_compra.py +55 -0
- sienge_python-0.1.0/examples/relatorio_financeiro.py +61 -0
- sienge_python-0.1.0/pyproject.toml +50 -0
- sienge_python-0.1.0/sienge/__init__.py +52 -0
- sienge_python-0.1.0/sienge/auth.py +23 -0
- sienge_python-0.1.0/sienge/client.py +146 -0
- sienge_python-0.1.0/sienge/endpoints/__init__.py +27 -0
- sienge_python-0.1.0/sienge/endpoints/base.py +187 -0
- sienge_python-0.1.0/sienge/endpoints/bulk.py +264 -0
- sienge_python-0.1.0/sienge/endpoints/comercial.py +237 -0
- sienge_python-0.1.0/sienge/endpoints/contabilidade.py +165 -0
- sienge_python-0.1.0/sienge/endpoints/credores.py +75 -0
- sienge_python-0.1.0/sienge/endpoints/engenharia.py +200 -0
- sienge_python-0.1.0/sienge/endpoints/financeiro.py +361 -0
- sienge_python-0.1.0/sienge/endpoints/patrimonio.py +57 -0
- sienge_python-0.1.0/sienge/endpoints/suprimentos.py +280 -0
- sienge_python-0.1.0/sienge/endpoints/tabelas.py +121 -0
- sienge_python-0.1.0/sienge/endpoints/webhooks.py +52 -0
- sienge_python-0.1.0/sienge/exceptions.py +40 -0
- sienge_python-0.1.0/sienge/models/__init__.py +17 -0
- sienge_python-0.1.0/sienge/models/comercial.py +103 -0
- sienge_python-0.1.0/sienge/models/credores.py +50 -0
- sienge_python-0.1.0/sienge/models/financeiro.py +179 -0
- sienge_python-0.1.0/sienge/models/obra.py +76 -0
- sienge_python-0.1.0/sienge/models/suprimentos.py +137 -0
- sienge_python-0.1.0/sienge/rate_limiter.py +84 -0
- sienge_python-0.1.0/sienge/utils.py +118 -0
- sienge_python-0.1.0/tests/__init__.py +0 -0
- sienge_python-0.1.0/tests/test_models.py +268 -0
- sienge_python-0.1.0/tests/test_utils.py +96 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
tags: ["v*"]
|
|
7
|
+
pull_request:
|
|
8
|
+
branches: [main]
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
test:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
strategy:
|
|
14
|
+
matrix:
|
|
15
|
+
python-version: ["3.10", "3.11", "3.12", "3.13"]
|
|
16
|
+
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v4
|
|
19
|
+
|
|
20
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
21
|
+
uses: actions/setup-python@v5
|
|
22
|
+
with:
|
|
23
|
+
python-version: ${{ matrix.python-version }}
|
|
24
|
+
|
|
25
|
+
- name: Install dependencies
|
|
26
|
+
run: |
|
|
27
|
+
python -m pip install --upgrade pip
|
|
28
|
+
pip install -e ".[dev]"
|
|
29
|
+
|
|
30
|
+
- name: Run tests
|
|
31
|
+
run: python -m pytest tests/ -v
|
|
32
|
+
|
|
33
|
+
publish:
|
|
34
|
+
needs: test
|
|
35
|
+
runs-on: ubuntu-latest
|
|
36
|
+
if: startsWith(github.ref, 'refs/tags/v')
|
|
37
|
+
permissions:
|
|
38
|
+
id-token: write
|
|
39
|
+
|
|
40
|
+
steps:
|
|
41
|
+
- uses: actions/checkout@v4
|
|
42
|
+
|
|
43
|
+
- name: Set up Python
|
|
44
|
+
uses: actions/setup-python@v5
|
|
45
|
+
with:
|
|
46
|
+
python-version: "3.12"
|
|
47
|
+
|
|
48
|
+
- name: Install build tools
|
|
49
|
+
run: pip install build
|
|
50
|
+
|
|
51
|
+
- name: Build package
|
|
52
|
+
run: python -m build
|
|
53
|
+
|
|
54
|
+
- name: Publish to PyPI
|
|
55
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 CONIN Engenharia
|
|
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,208 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sienge-python
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Cliente Python para a API REST do Sienge — ERP de construcao civil
|
|
5
|
+
Project-URL: Homepage, https://github.com/conin-engenharia/sienge-python
|
|
6
|
+
Project-URL: Documentation, https://github.com/conin-engenharia/sienge-python#readme
|
|
7
|
+
Project-URL: Repository, https://github.com/conin-engenharia/sienge-python
|
|
8
|
+
Project-URL: Issues, https://github.com/conin-engenharia/sienge-python/issues
|
|
9
|
+
Author-email: CONIN Engenharia <amora@conin-ia.com.br>
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: api,civil,construcao,erp,python,sienge,wrapper
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Office/Business
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
|
+
Requires-Python: >=3.10
|
|
25
|
+
Requires-Dist: requests>=2.28.0
|
|
26
|
+
Provides-Extra: dev
|
|
27
|
+
Requires-Dist: pytest-cov>=4.0; extra == 'dev'
|
|
28
|
+
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
29
|
+
Requires-Dist: python-dotenv>=1.0; extra == 'dev'
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
<p align="center">
|
|
33
|
+
<img src="assets/logo-conin.png" alt="CONIN Engenharia" width="400">
|
|
34
|
+
</p>
|
|
35
|
+
|
|
36
|
+
<h1 align="center">sienge-python</h1>
|
|
37
|
+
|
|
38
|
+
<p align="center">
|
|
39
|
+
<strong>Primeiro cliente Python para a API REST do Sienge</strong> — o ERP mais usado na construcao civil brasileira.<br>
|
|
40
|
+
<em>The first Python client for the Sienge REST API — Brazil's leading construction ERP.</em>
|
|
41
|
+
</p>
|
|
42
|
+
|
|
43
|
+
<p align="center">
|
|
44
|
+
<a href="https://github.com/conin-engenharia/sienge-python/actions"><img src="https://github.com/conin-engenharia/sienge-python/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
|
|
45
|
+
<a href="https://github.com/conin-engenharia/sienge-python/blob/main/LICENSE"><img src="https://img.shields.io/github/license/conin-engenharia/sienge-python" alt="License"></a>
|
|
46
|
+
</p>
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## O que e este projeto?
|
|
51
|
+
|
|
52
|
+
O [Sienge](https://www.sienge.com.br/) e o sistema de gestao (ERP) mais utilizado por construtoras no Brasil. Ele gerencia obras, financeiro, compras, contabilidade e outros processos da construcao civil. A plataforma disponibiliza uma **API REST** que permite integrar esses dados com sistemas externos.
|
|
53
|
+
|
|
54
|
+
O **sienge-python** e um cliente Python que simplifica essa integracao. A biblioteca cuida de autenticacao, paginacao, controle de limites de requisicao e tratamento de erros — permitindo que o desenvolvedor acesse os dados do Sienge com poucas linhas de codigo.
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
from sienge import SiengeClient
|
|
58
|
+
|
|
59
|
+
client = SiengeClient("sua-empresa", "usuario-api", "senha-api")
|
|
60
|
+
titulos = client.financeiro.list_titulos(start_date="2026-01-01")
|
|
61
|
+
|
|
62
|
+
for t in titulos:
|
|
63
|
+
print(f"{t.numero_documento}: R$ {t.valor_total:,.2f}")
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## Instalacao / Installation
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
pip install sienge-python
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Ou direto do repositorio / Or from source:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
pip install git+https://github.com/conin-engenharia/sienge-python.git
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Uso Rapido / Quick Start
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
from sienge import SiengeClient
|
|
84
|
+
|
|
85
|
+
client = SiengeClient("sua-empresa", "usuario-api", "senha-api")
|
|
86
|
+
|
|
87
|
+
# Listar obras / List buildings
|
|
88
|
+
obras = client.engenharia.list_obras()
|
|
89
|
+
for obra in obras:
|
|
90
|
+
print(f"{obra.nome} — {obra.tipo}")
|
|
91
|
+
|
|
92
|
+
# Titulos a pagar / Bills
|
|
93
|
+
titulos = client.financeiro.list_titulos(start_date="2026-01-01")
|
|
94
|
+
total = sum(t.valor_total for t in titulos)
|
|
95
|
+
print(f"Total a pagar: R$ {total:,.2f}")
|
|
96
|
+
|
|
97
|
+
# Centros de custo / Cost centers
|
|
98
|
+
centros = client.financeiro.search_centros_custo("Obra Centro")
|
|
99
|
+
|
|
100
|
+
# Pedidos de compra / Purchase orders
|
|
101
|
+
pedidos = client.suprimentos.list_pedidos(building_id=123)
|
|
102
|
+
|
|
103
|
+
# Fornecedores / Suppliers
|
|
104
|
+
fornecedores = client.credores.list_credores()
|
|
105
|
+
|
|
106
|
+
# Contabilidade / Accounting
|
|
107
|
+
lancamentos = client.contabilidade.list_lancamentos(company_id=1, start_date="2026-01-01")
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Via variaveis de ambiente / Environment variables
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
export SIENGE_SUBDOMAIN=sua-empresa
|
|
114
|
+
export SIENGE_USERNAME=usuario-api
|
|
115
|
+
export SIENGE_PASSWORD=senha-api
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
from sienge import SiengeClient
|
|
120
|
+
client = SiengeClient.from_env()
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Modulos Disponiveis / Available Modules
|
|
124
|
+
|
|
125
|
+
| Modulo | Acesso | Funcionalidades |
|
|
126
|
+
|--------|--------|-----------------|
|
|
127
|
+
| **Engenharia** | `client.engenharia` | Obras, progresso, orcamento, diarios, canteiros, bases de custo |
|
|
128
|
+
| **Financeiro** | `client.financeiro` | Titulos, fluxo de caixa, contas bancarias, saldos, centros de custo, NF-e |
|
|
129
|
+
| **Suprimentos** | `client.suprimentos` | Pedidos de compra (CRUD), notas fiscais, contratos, estoque, cotacoes |
|
|
130
|
+
| **Comercial** | `client.comercial` | Clientes, contratos, unidades, mapa imobiliario, tipos de imovel |
|
|
131
|
+
| **Contabilidade** | `client.contabilidade` | Lancamentos, plano de contas, lotes, fechamento, empresas |
|
|
132
|
+
| **Credores** | `client.credores` | Fornecedores, info bancaria |
|
|
133
|
+
| **Patrimonio** | `client.patrimonio` | Ativos fixos, moveis, alugueis |
|
|
134
|
+
| **Webhooks** | `client.webhooks` | Cadastro e gerenciamento de notificacoes (10 eventos) |
|
|
135
|
+
| **Tabelas** | `client.tabelas` | Cidades, profissoes, marcas, unidades de medida, indexadores |
|
|
136
|
+
| **Bulk Data** | `client.bulk` | 12 endpoints de exportacao em massa (plano Ultimate) |
|
|
137
|
+
|
|
138
|
+
## Features
|
|
139
|
+
|
|
140
|
+
- **Type hints completos** — Dataclasses tipadas para todos os recursos
|
|
141
|
+
- **Rate limiting automatico** — 200 req/min REST, 20 req/min Bulk
|
|
142
|
+
- **Retry com backoff exponencial** — Resiliencia contra erros transientes
|
|
143
|
+
- **Paginacao automatica** — Iterators que buscam todas as paginas
|
|
144
|
+
- **Tratamento de erros** — Excecoes especificas: `AuthError`, `RateLimitError`, `NotFoundError`
|
|
145
|
+
- **Thread-safe** — Rate limiter com locks
|
|
146
|
+
|
|
147
|
+
## Excecoes / Exceptions
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
from sienge import SiengeError, AuthError, RateLimitError, NotFoundError
|
|
151
|
+
|
|
152
|
+
try:
|
|
153
|
+
obra = client.engenharia.get_obra(999)
|
|
154
|
+
except AuthError:
|
|
155
|
+
print("Credenciais invalidas ou recurso nao liberado")
|
|
156
|
+
except NotFoundError:
|
|
157
|
+
print("Obra nao encontrada")
|
|
158
|
+
except RateLimitError as e:
|
|
159
|
+
print(f"Rate limit — retry em {e.retry_after}s")
|
|
160
|
+
except SiengeError as e:
|
|
161
|
+
print(f"Erro: {e}")
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Paginacao Automatica / Auto-pagination
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
# Itera sobre TODOS os centros de custo (3000+) automaticamente
|
|
168
|
+
for cc in client.financeiro.iter_centros_custo():
|
|
169
|
+
print(f"{cc.codigo}: {cc.nome}")
|
|
170
|
+
|
|
171
|
+
# Ou limitar resultados
|
|
172
|
+
primeiros_50 = client.financeiro.list_centros_custo(limit=50)
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Pre-requisitos / Prerequisites
|
|
176
|
+
|
|
177
|
+
- Python 3.10+
|
|
178
|
+
- Conta de cliente **Data Center** do Sienge
|
|
179
|
+
- Usuario de API criado no painel Sienge (Menu > APIs e Conectores > Usuarios de API)
|
|
180
|
+
- Recursos necessarios liberados para o usuario (aba "Autorizacoes")
|
|
181
|
+
|
|
182
|
+
## Planos de API / API Plans
|
|
183
|
+
|
|
184
|
+
| Plano | Limite REST/dia | Limite Bulk/dia |
|
|
185
|
+
|-------|-----------------|-----------------|
|
|
186
|
+
| Free | 100 | 10 |
|
|
187
|
+
| Start | 1.000 | 100 |
|
|
188
|
+
| Essential | 5.000 | 500 |
|
|
189
|
+
| Enterprise | 10.000 | 1.000 |
|
|
190
|
+
| Ultimate | 75.000 | 7.500 |
|
|
191
|
+
|
|
192
|
+
## Contribuindo / Contributing
|
|
193
|
+
|
|
194
|
+
1. Fork o repositorio
|
|
195
|
+
2. Crie uma branch (`git checkout -b feature/minha-feature`)
|
|
196
|
+
3. Commit (`git commit -m 'Adiciona minha feature'`)
|
|
197
|
+
4. Push (`git push origin feature/minha-feature`)
|
|
198
|
+
5. Abra um Pull Request
|
|
199
|
+
|
|
200
|
+
## Licenca / License
|
|
201
|
+
|
|
202
|
+
MIT License — veja [LICENSE](LICENSE).
|
|
203
|
+
|
|
204
|
+
## Sobre / About
|
|
205
|
+
|
|
206
|
+
Desenvolvido pela [CONIN Engenharia](https://conin-ia.com.br) para automatizar operacoes de construcao civil com o Sienge.
|
|
207
|
+
|
|
208
|
+
*Built by CONIN Engenharia to automate construction operations with Sienge ERP.*
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="assets/logo-conin.png" alt="CONIN Engenharia" width="400">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">sienge-python</h1>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<strong>Primeiro cliente Python para a API REST do Sienge</strong> — o ERP mais usado na construcao civil brasileira.<br>
|
|
9
|
+
<em>The first Python client for the Sienge REST API — Brazil's leading construction ERP.</em>
|
|
10
|
+
</p>
|
|
11
|
+
|
|
12
|
+
<p align="center">
|
|
13
|
+
<a href="https://github.com/conin-engenharia/sienge-python/actions"><img src="https://github.com/conin-engenharia/sienge-python/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
|
|
14
|
+
<a href="https://github.com/conin-engenharia/sienge-python/blob/main/LICENSE"><img src="https://img.shields.io/github/license/conin-engenharia/sienge-python" alt="License"></a>
|
|
15
|
+
</p>
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## O que e este projeto?
|
|
20
|
+
|
|
21
|
+
O [Sienge](https://www.sienge.com.br/) e o sistema de gestao (ERP) mais utilizado por construtoras no Brasil. Ele gerencia obras, financeiro, compras, contabilidade e outros processos da construcao civil. A plataforma disponibiliza uma **API REST** que permite integrar esses dados com sistemas externos.
|
|
22
|
+
|
|
23
|
+
O **sienge-python** e um cliente Python que simplifica essa integracao. A biblioteca cuida de autenticacao, paginacao, controle de limites de requisicao e tratamento de erros — permitindo que o desenvolvedor acesse os dados do Sienge com poucas linhas de codigo.
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
from sienge import SiengeClient
|
|
27
|
+
|
|
28
|
+
client = SiengeClient("sua-empresa", "usuario-api", "senha-api")
|
|
29
|
+
titulos = client.financeiro.list_titulos(start_date="2026-01-01")
|
|
30
|
+
|
|
31
|
+
for t in titulos:
|
|
32
|
+
print(f"{t.numero_documento}: R$ {t.valor_total:,.2f}")
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## Instalacao / Installation
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pip install sienge-python
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Ou direto do repositorio / Or from source:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pip install git+https://github.com/conin-engenharia/sienge-python.git
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Uso Rapido / Quick Start
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
from sienge import SiengeClient
|
|
53
|
+
|
|
54
|
+
client = SiengeClient("sua-empresa", "usuario-api", "senha-api")
|
|
55
|
+
|
|
56
|
+
# Listar obras / List buildings
|
|
57
|
+
obras = client.engenharia.list_obras()
|
|
58
|
+
for obra in obras:
|
|
59
|
+
print(f"{obra.nome} — {obra.tipo}")
|
|
60
|
+
|
|
61
|
+
# Titulos a pagar / Bills
|
|
62
|
+
titulos = client.financeiro.list_titulos(start_date="2026-01-01")
|
|
63
|
+
total = sum(t.valor_total for t in titulos)
|
|
64
|
+
print(f"Total a pagar: R$ {total:,.2f}")
|
|
65
|
+
|
|
66
|
+
# Centros de custo / Cost centers
|
|
67
|
+
centros = client.financeiro.search_centros_custo("Obra Centro")
|
|
68
|
+
|
|
69
|
+
# Pedidos de compra / Purchase orders
|
|
70
|
+
pedidos = client.suprimentos.list_pedidos(building_id=123)
|
|
71
|
+
|
|
72
|
+
# Fornecedores / Suppliers
|
|
73
|
+
fornecedores = client.credores.list_credores()
|
|
74
|
+
|
|
75
|
+
# Contabilidade / Accounting
|
|
76
|
+
lancamentos = client.contabilidade.list_lancamentos(company_id=1, start_date="2026-01-01")
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Via variaveis de ambiente / Environment variables
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
export SIENGE_SUBDOMAIN=sua-empresa
|
|
83
|
+
export SIENGE_USERNAME=usuario-api
|
|
84
|
+
export SIENGE_PASSWORD=senha-api
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
from sienge import SiengeClient
|
|
89
|
+
client = SiengeClient.from_env()
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Modulos Disponiveis / Available Modules
|
|
93
|
+
|
|
94
|
+
| Modulo | Acesso | Funcionalidades |
|
|
95
|
+
|--------|--------|-----------------|
|
|
96
|
+
| **Engenharia** | `client.engenharia` | Obras, progresso, orcamento, diarios, canteiros, bases de custo |
|
|
97
|
+
| **Financeiro** | `client.financeiro` | Titulos, fluxo de caixa, contas bancarias, saldos, centros de custo, NF-e |
|
|
98
|
+
| **Suprimentos** | `client.suprimentos` | Pedidos de compra (CRUD), notas fiscais, contratos, estoque, cotacoes |
|
|
99
|
+
| **Comercial** | `client.comercial` | Clientes, contratos, unidades, mapa imobiliario, tipos de imovel |
|
|
100
|
+
| **Contabilidade** | `client.contabilidade` | Lancamentos, plano de contas, lotes, fechamento, empresas |
|
|
101
|
+
| **Credores** | `client.credores` | Fornecedores, info bancaria |
|
|
102
|
+
| **Patrimonio** | `client.patrimonio` | Ativos fixos, moveis, alugueis |
|
|
103
|
+
| **Webhooks** | `client.webhooks` | Cadastro e gerenciamento de notificacoes (10 eventos) |
|
|
104
|
+
| **Tabelas** | `client.tabelas` | Cidades, profissoes, marcas, unidades de medida, indexadores |
|
|
105
|
+
| **Bulk Data** | `client.bulk` | 12 endpoints de exportacao em massa (plano Ultimate) |
|
|
106
|
+
|
|
107
|
+
## Features
|
|
108
|
+
|
|
109
|
+
- **Type hints completos** — Dataclasses tipadas para todos os recursos
|
|
110
|
+
- **Rate limiting automatico** — 200 req/min REST, 20 req/min Bulk
|
|
111
|
+
- **Retry com backoff exponencial** — Resiliencia contra erros transientes
|
|
112
|
+
- **Paginacao automatica** — Iterators que buscam todas as paginas
|
|
113
|
+
- **Tratamento de erros** — Excecoes especificas: `AuthError`, `RateLimitError`, `NotFoundError`
|
|
114
|
+
- **Thread-safe** — Rate limiter com locks
|
|
115
|
+
|
|
116
|
+
## Excecoes / Exceptions
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
from sienge import SiengeError, AuthError, RateLimitError, NotFoundError
|
|
120
|
+
|
|
121
|
+
try:
|
|
122
|
+
obra = client.engenharia.get_obra(999)
|
|
123
|
+
except AuthError:
|
|
124
|
+
print("Credenciais invalidas ou recurso nao liberado")
|
|
125
|
+
except NotFoundError:
|
|
126
|
+
print("Obra nao encontrada")
|
|
127
|
+
except RateLimitError as e:
|
|
128
|
+
print(f"Rate limit — retry em {e.retry_after}s")
|
|
129
|
+
except SiengeError as e:
|
|
130
|
+
print(f"Erro: {e}")
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Paginacao Automatica / Auto-pagination
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
# Itera sobre TODOS os centros de custo (3000+) automaticamente
|
|
137
|
+
for cc in client.financeiro.iter_centros_custo():
|
|
138
|
+
print(f"{cc.codigo}: {cc.nome}")
|
|
139
|
+
|
|
140
|
+
# Ou limitar resultados
|
|
141
|
+
primeiros_50 = client.financeiro.list_centros_custo(limit=50)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Pre-requisitos / Prerequisites
|
|
145
|
+
|
|
146
|
+
- Python 3.10+
|
|
147
|
+
- Conta de cliente **Data Center** do Sienge
|
|
148
|
+
- Usuario de API criado no painel Sienge (Menu > APIs e Conectores > Usuarios de API)
|
|
149
|
+
- Recursos necessarios liberados para o usuario (aba "Autorizacoes")
|
|
150
|
+
|
|
151
|
+
## Planos de API / API Plans
|
|
152
|
+
|
|
153
|
+
| Plano | Limite REST/dia | Limite Bulk/dia |
|
|
154
|
+
|-------|-----------------|-----------------|
|
|
155
|
+
| Free | 100 | 10 |
|
|
156
|
+
| Start | 1.000 | 100 |
|
|
157
|
+
| Essential | 5.000 | 500 |
|
|
158
|
+
| Enterprise | 10.000 | 1.000 |
|
|
159
|
+
| Ultimate | 75.000 | 7.500 |
|
|
160
|
+
|
|
161
|
+
## Contribuindo / Contributing
|
|
162
|
+
|
|
163
|
+
1. Fork o repositorio
|
|
164
|
+
2. Crie uma branch (`git checkout -b feature/minha-feature`)
|
|
165
|
+
3. Commit (`git commit -m 'Adiciona minha feature'`)
|
|
166
|
+
4. Push (`git push origin feature/minha-feature`)
|
|
167
|
+
5. Abra um Pull Request
|
|
168
|
+
|
|
169
|
+
## Licenca / License
|
|
170
|
+
|
|
171
|
+
MIT License — veja [LICENSE](LICENSE).
|
|
172
|
+
|
|
173
|
+
## Sobre / About
|
|
174
|
+
|
|
175
|
+
Desenvolvido pela [CONIN Engenharia](https://conin-ia.com.br) para automatizar operacoes de construcao civil com o Sienge.
|
|
176
|
+
|
|
177
|
+
*Built by CONIN Engenharia to automate construction operations with Sienge ERP.*
|
|
Binary file
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Exemplo: Consultar obra no Sienge.
|
|
4
|
+
|
|
5
|
+
Uso:
|
|
6
|
+
export SIENGE_SUBDOMAIN=sua-empresa
|
|
7
|
+
export SIENGE_USERNAME=usuario-api
|
|
8
|
+
export SIENGE_PASSWORD=senha-api
|
|
9
|
+
|
|
10
|
+
python consultar_obra.py "Recofarma"
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import sys
|
|
14
|
+
from dotenv import load_dotenv
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
|
|
17
|
+
load_dotenv()
|
|
18
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
|
19
|
+
|
|
20
|
+
from sienge import SiengeClient, SiengeError
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def main():
|
|
24
|
+
client = SiengeClient.from_env()
|
|
25
|
+
nome = sys.argv[1] if len(sys.argv) > 1 else ""
|
|
26
|
+
|
|
27
|
+
if nome:
|
|
28
|
+
print(f"Buscando obra: {nome}")
|
|
29
|
+
obras = client.engenharia.search_obra(nome)
|
|
30
|
+
else:
|
|
31
|
+
print("Listando todas as obras...")
|
|
32
|
+
obras = client.engenharia.list_obras(limit=20)
|
|
33
|
+
|
|
34
|
+
if not obras:
|
|
35
|
+
print("Nenhuma obra encontrada.")
|
|
36
|
+
return
|
|
37
|
+
|
|
38
|
+
for obra in obras:
|
|
39
|
+
print(f"\n--- {obra.nome} (ID: {obra.id}) ---")
|
|
40
|
+
print(f" Tipo: {obra.tipo}")
|
|
41
|
+
if obra.endereco:
|
|
42
|
+
print(f" Endereco: {obra.endereco}")
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
if __name__ == "__main__":
|
|
46
|
+
try:
|
|
47
|
+
main()
|
|
48
|
+
except SiengeError as e:
|
|
49
|
+
print(f"Erro Sienge: {e}")
|
|
50
|
+
sys.exit(1)
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Exemplo: Listar pedidos de compra de uma obra.
|
|
4
|
+
|
|
5
|
+
Uso:
|
|
6
|
+
export SIENGE_SUBDOMAIN=sua-empresa
|
|
7
|
+
export SIENGE_USERNAME=usuario-api
|
|
8
|
+
export SIENGE_PASSWORD=senha-api
|
|
9
|
+
|
|
10
|
+
python pedido_compra.py [building_id]
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import sys
|
|
14
|
+
from dotenv import load_dotenv
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
|
|
17
|
+
load_dotenv()
|
|
18
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
|
19
|
+
|
|
20
|
+
from sienge import SiengeClient, SiengeError
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def main():
|
|
24
|
+
client = SiengeClient.from_env()
|
|
25
|
+
|
|
26
|
+
building_id = int(sys.argv[1]) if len(sys.argv) > 1 else None
|
|
27
|
+
|
|
28
|
+
if building_id:
|
|
29
|
+
print(f"Pedidos de compra da obra #{building_id}")
|
|
30
|
+
else:
|
|
31
|
+
print("Todos os pedidos de compra")
|
|
32
|
+
print("=" * 50)
|
|
33
|
+
|
|
34
|
+
pedidos = client.suprimentos.list_pedidos(building_id=building_id, limit=50)
|
|
35
|
+
|
|
36
|
+
if not pedidos:
|
|
37
|
+
print("Nenhum pedido encontrado.")
|
|
38
|
+
return
|
|
39
|
+
|
|
40
|
+
for p in pedidos:
|
|
41
|
+
print(f"\nPedido {p.numero_formatado} (ID: {p.id})")
|
|
42
|
+
print(f" Fornecedor ID: {p.fornecedor_id}")
|
|
43
|
+
print(f" Status: {p.status}")
|
|
44
|
+
print(f" Autorizado: {p.autorizado}")
|
|
45
|
+
|
|
46
|
+
print(f"\n{'=' * 50}")
|
|
47
|
+
print(f"Total: {len(pedidos)} pedidos")
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
if __name__ == "__main__":
|
|
51
|
+
try:
|
|
52
|
+
main()
|
|
53
|
+
except SiengeError as e:
|
|
54
|
+
print(f"Erro Sienge: {e}")
|
|
55
|
+
sys.exit(1)
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Exemplo: Relatorio financeiro — titulos a pagar.
|
|
4
|
+
|
|
5
|
+
Uso:
|
|
6
|
+
export SIENGE_SUBDOMAIN=sua-empresa
|
|
7
|
+
export SIENGE_USERNAME=usuario-api
|
|
8
|
+
export SIENGE_PASSWORD=senha-api
|
|
9
|
+
|
|
10
|
+
python relatorio_financeiro.py [YYYY-MM-DD] [YYYY-MM-DD]
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import sys
|
|
14
|
+
from datetime import datetime, timedelta
|
|
15
|
+
from dotenv import load_dotenv
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
|
|
18
|
+
load_dotenv()
|
|
19
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
|
20
|
+
|
|
21
|
+
from sienge import SiengeClient, SiengeError
|
|
22
|
+
from sienge.utils import format_currency
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def main():
|
|
26
|
+
client = SiengeClient.from_env()
|
|
27
|
+
|
|
28
|
+
end_date = sys.argv[2] if len(sys.argv) > 2 else datetime.now().strftime("%Y-%m-%d")
|
|
29
|
+
start_date = sys.argv[1] if len(sys.argv) > 1 else (datetime.now() - timedelta(days=30)).strftime("%Y-%m-%d")
|
|
30
|
+
|
|
31
|
+
print(f"Relatorio Financeiro: {start_date} a {end_date}")
|
|
32
|
+
print("=" * 50)
|
|
33
|
+
|
|
34
|
+
titulos = client.financeiro.list_titulos(start_date=start_date, end_date=end_date)
|
|
35
|
+
print(f"\nTitulos a pagar: {len(titulos)}")
|
|
36
|
+
|
|
37
|
+
total = sum(t.valor_total for t in titulos)
|
|
38
|
+
print(f"Valor total: {format_currency(total)}")
|
|
39
|
+
|
|
40
|
+
# Agrupar por status
|
|
41
|
+
por_status: dict[str, list] = {}
|
|
42
|
+
for t in titulos:
|
|
43
|
+
s = t.status or "?"
|
|
44
|
+
por_status.setdefault(s, []).append(t)
|
|
45
|
+
|
|
46
|
+
for status, grupo in sorted(por_status.items()):
|
|
47
|
+
subtotal = sum(t.valor_total for t in grupo)
|
|
48
|
+
print(f" Status '{status}': {len(grupo)} titulos — {format_currency(subtotal)}")
|
|
49
|
+
|
|
50
|
+
# Top 10 maiores
|
|
51
|
+
print(f"\nTop 10 maiores titulos:")
|
|
52
|
+
for t in sorted(titulos, key=lambda x: x.valor_total, reverse=True)[:10]:
|
|
53
|
+
print(f" {t.numero_documento}: {format_currency(t.valor_total)} (credor #{t.credor_id})")
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
if __name__ == "__main__":
|
|
57
|
+
try:
|
|
58
|
+
main()
|
|
59
|
+
except SiengeError as e:
|
|
60
|
+
print(f"Erro Sienge: {e}")
|
|
61
|
+
sys.exit(1)
|