Skip to main content

neoscr

Install

pip install neoscr

How to use

Fill me in please! Don’t forget code examples:

from neoscr.core import ConsultaSCR
import os

scr = ConsultaSCR(
    user=os.environ["SCR_USER"],
    password=os.environ["SCR_PASSWORD"],
    code=os.environ["SCR_CODE"],
    api_key=os.environ["SCR_API_KEY"]
)

Warning

You have the choice to not pass the API credentials on the ConsultaSCR instantiation, but for that you should have the credentials to access the SCR API stored in your OS environment variables.

cpf = "867.168.046-09" # fake cpf
ano = 2022
mes = 12

# retorna três dataframes
df_cpf_traduzido, df_cpf_modalidade, df_cpf_resumo_lista_das_operacoes = scr.get_cpf_data(cpf, ano, mes)

Note

neoscr will save each request made into .neoscr folder located at your home directory.

For the example above, the saved file will be: ~/.neoscr/86716804609_2022_12.json

Next time you do the same request, it will load from the local storage.

cnpj = "79.322.561/0001-67" # fake cnpj
ano = 2022
mes = 12

# retorna três dataframes
df_cnpj_traduzido, df_cnpj_modalidade, df_cnpj_resumo_lista_das_operacoes = scr.get_cnpj_data(cnpj, ano, mes)

Batch Query

Execute the code below to query a list of cpfs or cnpjs (under modification) and download the data

Caution

Please don’t just copy and execute the code above. Read it and adapt it to your needs.

import os
import logging
import pandas as pd
from tqdm import tqdm

from neoscr.utils import let_only_digits

# carregando a lista de cpfs
df = pd.read_csv("dataset.csv")
lista_de_cpfs = df['cpf'].tolist()

# instanciando o objeto ConsultaSCR
scr = ConsultaSCR()

# instanciando o objeto logger
logger = logging.getLogger('database_updater')
logger.setLevel(logging.DEBUG)

# criando o file handler
file_handler = logging.FileHandler('querylog.log')
file_handler.setLevel(logging.DEBUG)

# adicionando o file handler ao logger
logger.addHandler(file_handler)

# iterando sobre a lista de cpfs e enriquecendo
ano = 2022
mes = 12
for cpf in tqdm(lista_de_cpfs):
    try:
        df_traduzido, df_modalidade, df_cnpj_resumo_lista_das_operacoes = scr.get_cpf_data(cpf, ano, mes)                               
        cpf_only_digits = let_only_digits(cpf)
        df_traduzido.to_csv(f"data/scr/raw/{cpf_only_digits}_traduzido.csv", index=False)
        df_modalidade.to_csv(f"data/scr/raw/{cpf_only_digits}_modalidade.csv", index=False)
        df_cnpj_resumo_lista_das_operacoes.to_csv(f"data/scr/raw/{cpf_only_digits}_resumo_lista_das_operacoes.csv", index=False)
    except:
        logger.error(f"Erro no CPF {cpf}")
        continue

After download the data, you may want to get all the raw data together in one big table:

# carregandos os dados de todos os arquivos salvos
df_traduzido_full = pd.DataFrame()
for file in os.listdir("data/scr/raw/"):
    if file.endswith("_traduzido.csv"):
        df_traduzido = pd.read_csv(f"data/scr/raw/{file}")
        df_traduzido_full = pd.concat([df_traduzido_full, df_traduzido])

df_modalidade_full = pd.DataFrame()
for file in os.listdir(".data/scr/raw"):
    if file.endswith("_modalidade.csv"):
        df_modalidade = pd.read_csv(f"data/scr/raw/{file}")
        df_modalidade_full = pd.concat([df_modalidade_full, df_modalidade])

df_cnpj_resumo_lista_das_operacoes_full = pd.DataFrame()
for file in os.listdir("data/scr/raw/"):
    if file.endswith("_resumo_lista_das_operacoes.csv"):
        df_cnpj_resumo_lista_das_operacoes = pd.read_csv(f"data/scr/raw/{file}")
        df_cnpj_resumo_lista_das_operacoes_full = pd.concat([df_cnpj_resumo_lista_das_operacoes_full, df_cnpj_resumo_lista_das_operacoes])

Metadata

Release files for neoscr 2.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for neoscr 2.1.2
File Size Uploaded
neoscr-2.1.2.tar.gz 13.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for neoscr 2.1.2
File Interpreter ABI Platform
neoscr-2.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 25.6 kB

Release files / neoscr-2.1.2.tar.gz

Download URL neoscr-2.1.2.tar.gz
Size 13.5 kB
Tags Source
SHA-256 checksum
How to use checksums
67e389f690c65872d57c14adb340b370ef61cd25914268ff11d89030f082a543
BLAKE2b-256 checksum
How to use checksums
7cfbbc54c800d2db291074f6aa6584a46e3ffc9f5375aeb73e49e8650600ebc9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / neoscr-2.1.2-py3-none-any.whl

Download URL neoscr-2.1.2-py3-none-any.whl
Size 12.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
30d32623ad27052ccebd903caa9b822e9521b9fd07f34b642792ffc079b413c6
BLAKE2b-256 checksum
How to use checksums
1a00409494b1bd7042782597a59993d4989432a7894fbcb58facce7f6874f2ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release history Release notifications | RSS feed

This release

2.1.2 This release

2 release files

2.1.1

2 release files

2.1.0

2 release files

2.0.0

2 release files

1.0.0

2 release 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