bb_api 0.2.0__py3-none-any.whl
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.
- bb_api/__init__.py +17 -0
- bb_api/accountability.py +1870 -0
- bb_api/common.py +72 -0
- bb_api-0.2.0.dist-info/METADATA +54 -0
- bb_api-0.2.0.dist-info/RECORD +8 -0
- bb_api-0.2.0.dist-info/WHEEL +5 -0
- bb_api-0.2.0.dist-info/licenses/LICENSE +674 -0
- bb_api-0.2.0.dist-info/top_level.txt +1 -0
bb_api/common.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import re
|
|
2
|
+
import pandas as pd
|
|
3
|
+
from enum import Enum
|
|
4
|
+
from typing import Any, Dict, NewType, Sequence, Union
|
|
5
|
+
from datetime import date, datetime, timedelta
|
|
6
|
+
|
|
7
|
+
_dese_oauth_domain = "https://oauth.desenv.bb.com.br"
|
|
8
|
+
_homo_oauth_domain = "https://oauth.hm.bb.com.br"
|
|
9
|
+
_homo_alt_oauth_domain = "https://oauth.sandbox.bb.com.br"
|
|
10
|
+
_prod_oauth_domain = "https://oauth.bb.com.br"
|
|
11
|
+
|
|
12
|
+
_dese_api_domain = "https://api.desenv.bb.com.br"
|
|
13
|
+
_homo_api_domain = "https://api.hm.bb.com.br"
|
|
14
|
+
_homo_alt_api_domain = "https://api.sandbox.bb.com.br"
|
|
15
|
+
_prod_api_domain = "https://api.bb.com.br"
|
|
16
|
+
|
|
17
|
+
_time_between_access_token_requests = timedelta(minutes=10)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
DateLike = NewType("DateLike", Union[str | date | datetime])
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class Ambiente(Enum):
|
|
24
|
+
DESENVOLVIMENTO = 0
|
|
25
|
+
HOMOLOGACAO = 1
|
|
26
|
+
HOMOLOGACAO_ALTERNATIVO = 2
|
|
27
|
+
PRODUCAO = 3
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _get_headers(access_token: str) -> Dict:
|
|
31
|
+
return {
|
|
32
|
+
"Authorization": f"Bearer {access_token}",
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _handle_numeric_string_with_symbols(v: str) -> str:
|
|
37
|
+
return re.sub(r"\D", "", v)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _handle_dates(v: DateLike) -> str:
|
|
41
|
+
if isinstance(v, str):
|
|
42
|
+
v = datetime.strptime(v, "%Y-%m-%d")
|
|
43
|
+
elif isinstance(v, date):
|
|
44
|
+
v = datetime.combine(v, datetime.min.time())
|
|
45
|
+
|
|
46
|
+
v = v.strftime("%Y-%m-%d")
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _handle_results(
|
|
50
|
+
data: Any,
|
|
51
|
+
main_list: str = None,
|
|
52
|
+
insertables: Sequence[str] = None,
|
|
53
|
+
explodeables: Sequence[str] = None,
|
|
54
|
+
rename_dict: Dict[str, str] = None,
|
|
55
|
+
) -> pd.DataFrame:
|
|
56
|
+
if main_list is not None:
|
|
57
|
+
df = pd.DataFrame(data[main_list])
|
|
58
|
+
else:
|
|
59
|
+
df = pd.DataFrame([data])
|
|
60
|
+
|
|
61
|
+
if insertables is not None:
|
|
62
|
+
for insertable in insertables:
|
|
63
|
+
df[insertable] = data[insertable]
|
|
64
|
+
|
|
65
|
+
if explodeables is not None:
|
|
66
|
+
for explodeable in explodeables:
|
|
67
|
+
df = df.explode(explodeable, ignore_index=True)
|
|
68
|
+
|
|
69
|
+
if rename_dict is not None:
|
|
70
|
+
df = df.rename(rename_dict, axis=1)
|
|
71
|
+
|
|
72
|
+
return df
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: bb_api
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Wrapper da API do Banco do Brasil.
|
|
5
|
+
Requires-Python: >=3.13
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: pandas>=3.0.1
|
|
9
|
+
Requires-Dist: requests>=2.32.5
|
|
10
|
+
Dynamic: license-file
|
|
11
|
+
|
|
12
|
+
# Biblioteca API BB
|
|
13
|
+
|
|
14
|
+
*Wrapper* da API do Banco do Brasil.
|
|
15
|
+
|
|
16
|
+
## Como instalar?
|
|
17
|
+
|
|
18
|
+
Se você usar o `uv`:
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
uv add bb_api
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Se você usar o `pip`:
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
pip install bb_api
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Funcionalidades
|
|
31
|
+
|
|
32
|
+
- Lê os parâmetros `app_key`, `client_id` e `client_secret` das variáveis de
|
|
33
|
+
ambiente `BB_API_APP_KEY`, `BB_API_CLIENT_ID` e `BB_API_CLIENT_SECRET`,
|
|
34
|
+
respectivamente, caso não sejam passadas na instanciação das classes
|
|
35
|
+
- Gera o token de acesso automaticamente, gerando um novo a cada 10 minutos,
|
|
36
|
+
tempo de expiração do token definido pelo Banco do Brasil
|
|
37
|
+
- Separa operaçãos disponíveis aos órgãos de repasse e de controle em classes
|
|
38
|
+
separadas, mantendo as operações comuns aos dois
|
|
39
|
+
- Retorna os resultados das chamadas às APIS em formato de `DataFrame` do
|
|
40
|
+
[`pandas`][pandas]
|
|
41
|
+
- Aceita parâmetros em múltiplos formatos, como:
|
|
42
|
+
- CNPJ e CEP podem estar pontuados ou não
|
|
43
|
+
- Datas podem estar em formato `str`, `date` ou `datetime`
|
|
44
|
+
|
|
45
|
+
## Referências
|
|
46
|
+
|
|
47
|
+
Os documentos utilizados de referência para criação dessa API foram:
|
|
48
|
+
|
|
49
|
+
- [Portal Developers BB]
|
|
50
|
+
- [Documentação Swagger API BB]
|
|
51
|
+
|
|
52
|
+
[pandas]: https://pandas.pydata.org/
|
|
53
|
+
[Portal Developers BB]: https://apoio.developers.bb.com.br/referency/post/641877548600960012b32cd6
|
|
54
|
+
[Documentação Swagger API BB]: https://api.bb.com.br/accountability/v3/swagger
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
bb_api/__init__.py,sha256=-FbqpkOfFWZEQRgbbWZPrg9CYTc5XlFycHq65LESC6Q,331
|
|
2
|
+
bb_api/accountability.py,sha256=CzEge1l5ew9OzBNMmtRzU5tnJ0FcCBKY6DJWESxj_Fo,74213
|
|
3
|
+
bb_api/common.py,sha256=B0_SxUV6TfVqtmB0w1I-VcvsW5Yl_3t7hmfuxeA3YM0,1901
|
|
4
|
+
bb_api-0.2.0.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
5
|
+
bb_api-0.2.0.dist-info/METADATA,sha256=i74yovYQY3m1hikCkV5Kpvjs1vVOZeg4Mxq08zZq4xA,1588
|
|
6
|
+
bb_api-0.2.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
7
|
+
bb_api-0.2.0.dist-info/top_level.txt,sha256=ZMdA0Lx6osrxQHw-iizi8tXTIofFtsg_qPApwC2xPOM,7
|
|
8
|
+
bb_api-0.2.0.dist-info/RECORD,,
|