babilonia.accounting#
Brazil-specific accounting classes and tax reference constants.
Provides data classes for parsing and analyzing bank statements from Banco do Brasil and Nubank, computing cash flow summaries, managing budget records, and loading NFSe XML invoices. Module-level constants hold the 2025 INSS and IRRF progressive tax tables.
Classes
|
Parses Banco do Brasil CDB investment statement text files. |
|
A record table for managing budget items. |
|
A primitive class for handling Cash flow analysis |
|
A class for handling CSV data from Banco do Brasil Conta Corrente. |
|
Class for handling BB-CC for PJ accoung CSV data. |
|
Class for handling BB-PP CSV data. |
|
A class for handling CSV data exported from Nubank Cartão de Crédito (Nubank credit card) invoices. |
|
Class for handling NFSe XML data. |
|
A collection of |
- class babilonia.accounting.Budget(name='MyBudget', alias='Bud')[source]#
Bases:
RecordTableA record table for managing budget items.
Extends
RecordTableto track revenues and expenses with support for contract grouping, payment status, due dates, and file attachments. Signed totals and per-status or per-contract summaries are recomputed automatically on update.
- class babilonia.accounting.CashFlow(name='CashFlow', alias='CF')[source]#
Bases:
DataSetA primitive class for handling Cash flow analysis
Cashflow Analysis Example
from babilonia.accounting import CashFlow # create an empty class cf = CashFlow() # set the file for CSV file_csv = "path/to/file.csv" # [change this] # load data cf.load_data(file_csv) # call method dc = cf.cashflow_analysis(df=cf.data, category="Custeio") # print data print(dc["monthly"]) print(dc["yearly"])
- static get_cashflow_analysis(df, category=None)[source]#
Perform cash flow analysis with monthly and yearly aggregation.
This method classifies cash flows into inputs and outputs, aggregates values on a monthly and yearly basis, and computes cumulative balances. The analysis is fully independent from class state and inheritance behavior.
- Parameters:
df (pandas.DataFrame) – Input cash flow data containing at least the columns
Data,CategoriaandValor.category (str or None) – Optional category filter. If
None, all categories are grouped under"Geral".
- Returns:
Dictionary with monthly and yearly cash flow summaries.
- Return type:
dict
- static enrich_time_index(df)[source]#
Add year and year-month time indices to the cash flow data.
This method extracts the calendar year and a
YYYY-MMmonthly identifier from theDatacolumn.- Parameters:
df (pandas.DataFrame) – Input cash flow data.
- Returns:
Copy of the input data with additional
AnoandMescolumns.- Return type:
pandas.DataFrame
- static classify_flows(df)[source]#
Classify cash flows as inputs or outputs.
Positive or zero values are classified as
"In"and negative values as"Out".- Parameters:
df (pandas.DataFrame) – Cash flow data containing a
Valorcolumn.- Returns:
Copy of the input data with an additional
Flowcolumn.- Return type:
pandas.DataFrame
- static filter_category(df, category)[source]#
Filter cash flow data by category.
If no category is provided, all records are grouped under the default category
"Geral".- Parameters:
df (pandas.DataFrame) – Cash flow data.
category (str or None) – Category name used to filter the data.
- Returns:
Tuple containing the filtered data and the resolved category name.
- Return type:
tuple
- static get_monthly_summary(df, category)[source]#
Compute monthly cash flow summaries for each year.
This method aggregates cash flow inputs and outputs on a monthly basis, ensures that all calendar months are present, and computes annual cumulative balances.
- Parameters:
df (pandas.DataFrame) – Cash flow data enriched with time indices and flow classification.
category (str) – Category name associated with the analysis.
- Returns:
Monthly cash flow summary table.
- Return type:
pandas.DataFrame
- static get_yearly_summary(df_monthly, category)[source]#
Compute yearly cash flow summaries.
This method aggregates monthly cash flow data into yearly totals and computes cumulative balances across years.
- Parameters:
df_monthly (pandas.DataFrame) – Monthly cash flow summary table.
category (str) – Category name associated with the analysis.
- Returns:
Yearly cash flow summary table.
- Return type:
pandas.DataFrame
- static get_cashflow_report(df, year=None, initial_cash=None)[source]#
Build a yearly cash flow panel and summary by category.
- Parameters:
df (pandas.DataFrame) – Cash flow DataFrame containing transactional data with date, category, and value information compatible with the
enrich_time_index,classify_flows, andcashflow_analysismethods.year (int, optional) – Year to be analyzed. If
None, the current calendar year (local time) is used.initial_cash (float, optional) – Initial account balance at the beginning of the selected year. If
None, defaults to0.0.
- Returns:
Dictionary containing:
"Pannel": monthly cash flow panel with totals, per-category flows, and running balance."Summary": yearly summary by category with total, mean, and percentage contribution to total inflows.- Return type:
dict
- class babilonia.accounting.CashFlowBBCC(name='CashFlowBBCC', alias='CFBBCC')[source]#
Bases:
CashFlowA class for handling CSV data from Banco do Brasil Conta Corrente.
Script example
from babilonia.accounting import CashFlowBBCC # create an empty class cf = CashFlowBBCC() # set the file for CSV file_csv = "path/to/file.csv" # [change this] # load data cf.load_data(file_csv) # standardize data cf.standardize() # print data print(cf.data.head(10)) # save data file_out = "path/to/output.csv" # [change this] cf.data.to_csv(file_out, sep=";", index=False)
- load_data(file_data)[source]#
Load raw data from bank CSV statement
- Parameters:
file_data (str or Path) – Bank statement CSV file path
- Returns:
None
- Return type:
None
- standardize(force=False)[source]#
Standardize data into canonical format.
- Parameters:
force – Rebuild parsed data even if it exists
- parse_data(df=None)[source]#
Parse data to canonical format
- Parameters:
df (
pandas.DataFrame) – Optional input data- Returns:
Formated data
- Return type:
pandas.DataFrame
- parse_date(series)[source]#
Parse BB date field from
DD/MM/YYYYto datetime.- Parameters:
series (
pandas.Series) – String series- Returns:
Datetime series
- Return type:
pandas.Series
- parse_valor(series)[source]#
Convert
Valorfield to float.Examples
Input
Output
5.000,005000.00-403,00-403.00- Parameters:
series (
pandas.Series) – String series- Returns:
Value series
- Return type:
pandas.Series
- class babilonia.accounting.CashFlowBBCCPJ(name='CashFlowBBCCPJ', alias='CFBBCCPJ')[source]#
Bases:
CashFlowBBCCClass for handling BB-CC for PJ accoung CSV data.
- class babilonia.accounting.CashFlowBBPP(name='CashFlowBBPP', alias='CFBBPP')[source]#
Bases:
CashFlowBBCCClass for handling BB-PP CSV data.
- parse_data(df=None)[source]#
Parse data to canonical format
- Parameters:
df (
pandas.DataFrame) – Optional input data- Returns:
Formated data
- Return type:
pandas.DataFrame
- class babilonia.accounting.CashFlowNUCredit(name='CashFlowNuCC', alias='CFNUCC', invert_sign=True)[source]#
Bases:
CashFlowA class for handling CSV data exported from Nubank Cartão de Crédito (Nubank credit card) invoices.
Nubank appears to export at least two CSV variants for the same
date,title,amountschema:Quoted, Brazilian-formatted values, e.g.
"1.234,56"or"- 41,97"(comma decimal separator, dot thousands separator, sometimes a space between the minus sign and the digits).Unquoted, international-formatted values, e.g.
1234.56or-6722.00(dot decimal separator, no thousands separator).
parse_valorauto-detects and normalizes both variants.Note on sign convention: Nubank reports purchases as positive
amountand payments/refunds (“Pagamento recebido”) as negative. By default this class inverts that sign when building the canonicalValorfield, so purchases become outflows (negativeValor, classified as"Out") and payments/refunds become inflows (positiveValor, classified as"In") — consistent with howCashFlow.classify_flows()is used for the BB accounts. Passinvert_sign=Falseat construction time to keep Nubank’s raw sign convention instead.Script example
from babilonia.accounting import CashFlowNuCC # create an empty class cf = CashFlowNuCC() # set the file for CSV file_csv = "path/to/file.csv" # [change this] # load data cf.load_data(file_csv) # standardize data cf.standardize() # print data print(cf.data.head(10)) # save data file_out = "path/to/output.csv" # [change this] cf.data.to_csv(file_out, sep=";", index=False)
- load_data(file_data)[source]#
Load raw data from the Nubank credit-card CSV export.
- Parameters:
file_data (str or Path) – Nubank credit-card CSV file path
- Returns:
None
- Return type:
None
- standardize(force=False)[source]#
Standardize data into canonical format.
- Parameters:
force – Rebuild parsed data even if it exists
- parse_data(df=None)[source]#
Parse data to canonical format
- Parameters:
df (
pandas.DataFrame) – Optional input data- Returns:
Formated data
- Return type:
pandas.DataFrame
- parse_date(series)[source]#
Parse Nubank date field from
YYYY-MM-DDto datetime.- Parameters:
series (
pandas.Series) – String series- Returns:
Datetime series
- Return type:
pandas.Series
- parse_valor(series)[source]#
Convert
amountfield to float, auto-detecting the CSV variant.Examples
Input
Output (before sign inversion)
"50,50"50.50"- 3.784,83"-3784.8369.9969.99-6722.00-6722.00- Parameters:
series (
pandas.Series) – String series- Returns:
Value series
- Return type:
pandas.Series
- class babilonia.accounting.BBCDB(name='BBCDB', alias='BBCDB')[source]#
Bases:
DataSetParses Banco do Brasil CDB investment statement text files.
Reads the plain-text report exported by BB for CDB DI and CDB Progressivo accounts and splits it into named sections (EXTRATO, SALDOS, DEPOSITOS, RENDIMENTOS), normalizing each into a
pandas.DataFrame. The result is stored inself.dataas a nested dictionary keyed by account then section name.
- class babilonia.accounting.NFSe(name='NFSeDataSet', alias='NFSe')[source]#
Bases:
DataSetClass for handling NFSe XML data.
- class babilonia.accounting.NFSeColl(base_object=<class 'babilonia.accounting.NFSe'>, name='MyNFeCollection', alias='NFeCol0')[source]#
Bases:
CollectionA collection of
NFSeobjects.Extends
Collectionto load and aggregate multiple NFSe XML files into a shared catalog, either from a folder or an explicit list of file paths.