csb43.csb43
¶
Note
license: GNU Lesser General Public License v3.0 (see LICENSE)
Parsing and validation utilites for the Spanish standard norm 43 by the “Consejo Superior Bancario” (CSB) / “Asociación Española de Banca” (AEB) for storing bank account transactions.
(es) Herramientas para leer y validar datos almacenados siguiendo la norma 43 del Consejo Superior Bancario (CSB) / Asociación Española de Banca (CSB).
See also
References:
File – (es) Fichero¶
- class csb43.csb43.File(fd: Optional[Iterable[bytes]] = None, **record_settings)¶
A CSB43 file
Create a
File
object from a file descriptor:>>> with open("csb_file.csb") as fd: ... f = File(fd) ... # do something with f ...
Create an empty
File
object:>>> f = File()
- __bytes__() → bytes¶
- Return type
representation of this object as CSB43 records (using \n as separator)
>>> import csb43.csb43 as csb >>> f = csb.File() >>> f.add_account(csb.Account()) >>> f.add_transaction(csb.Transaction()) >>> print(f) 11 000000000000000000000000000000 22 0000000000000000000001000000000000000000000000000000000000 88999999999999999999000002
- __init__(fd: Optional[Iterable[bytes]] = None, **record_settings)¶
- Parameters
fd (
file
) – a csb file**record_settings –
- Raises
- __iter__() → Iterator[bytes]¶
- Return type
iterator of all the CSB43 records that this object represents
>>> import csb43.csb43 as csb >>> f = csb.File() >>> f.add_account(csb.Account()) >>> f.add_transaction(csb.Transaction()) >>> for x in f: ... print(x) ... b'11 000000000000000000000000000000 ' b'22 0000000000000000000001000000000000000000000000000000000000 ' b'88999999999999999999000002 ' >>>
- property abstract: Optional[csb43.csb43.csb_file.ClosingFile]¶
- Return type
ClosingFile
file abstract
- add_account(record: Union[bytes, csb43.csb43.account.Account])¶
Add a new account
- Parameters
record (
Account
orbasestring
) – account record- Raises
csb43.utils.Csb43Exception
if record is not valid
- add_exchange(record, update=False)¶
Add a new additional exchange record to the last added transaction
- Parameters
- Raises
See also
- add_item(record)¶
Add a new additional item record to the last added transaction
- Parameters
record (
Item
orbasestring
) – item record- Raises
csb43.utils.Csb43Exception
when the record is impossible to parse, or if the maximum number of complementary items has been reached
See also
- add_transaction(record)¶
Add a new transaction to the last added account
- Parameters
record (
Transaction
orbasestring
) – transaction record- Raises
See also
- as_dict(decimal_fallback=None) → Dict[str, Any]¶
- Parameters
decimal_fallback – decimal number fallback representation
- Return type
a representation of this object as a
dict
. The keys will be localised
>>> import csb43.csb43 as csb >>> f = csb.File() >>> f.add_account(csb.Account()) >>> f.add_transaction(csb.Transaction()) >>> import pprint >>> pprint.pprint(f.as_dict()) {u'cuentas': [{u'balance_inicial': None, u'codigo_de_entidad': None, u'codigo_de_sucursal': None, u'divisa': None, u'fecha_de_comienzo': None, u'fecha_de_fin': None, u'modalidad_de_informacion': None, u'movimientos': [{u'cantidad': None, u'codigo_de_sucursal': None, u'concepto_comun': None, u'concepto_propio': None, u'fecha_de_operacion': None, u'fecha_valor': None, u'numero_del_documento': None, u'primera_referencia': None, u'segunda_referencia': None}], u'nombre_abreviado': None, u'numero_de_cuenta': None}]}
- close_account(record=None)¶
Close the current account
- Parameters
record (
ClosingAccount
orbasestring
) – csb record- Raises
csb43.utils.Csb43Exception
if record is not valid
See also
- close_file(record=None)¶
Close the file with a termination record
- Parameters
record (
ClosingFile
orbasestring
) – csb record- Raises
csb43.utils.Csb43Exception
if record is not valid
If record is None, a new abstract is generated:
>>> c = File() >>> c.is_closed() False >>> c.close_file() >>> c.is_closed() True >>> c.abstract.totalRecords 0 >>> c.add_account(Account()) >>> c.abstract.totalRecords 0 >>> c.close_file() >>> c.abstract.totalRecords 1 >>> c.is_closed() True
If record is not empty, the number of records of File must be coincident with the quantity given in record:
>>> c = File() >>> cf = ClosingFile() >>> cf.totalRecords = 5 >>> c.close_file(cf) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "csb43/csb43/csb_file.py", line 200, in close_file File "csb43/utils/utils.py", line 25, in raiseCsb43Exception raise exc csb43.utils.utils.Csb43Exception: registro de cierre de fichero incongruente: total de registros 5 != 1 >>>
- get_last_account() → csb43.csb43.account.Account¶
- Return type
the last added
Account
- showInfo(fd=<_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'>)¶
- Parameters
fd (
file
) – file descriptor where to write to
- class csb43.csb43.ClosingFile(record: Optional[bytes] = None, **record_settings)¶
A File abstract, given by a termination record
Create a
ClosingFile
object from a CSB43 string record:>>> record = '88999999999999999999000123 ' >>> c = ClosingFile(record)
From an empty object to a CSB43 string record:
>>> c = ClosingFile() >>> c.totalRecords = 123 >>> str(c) '88999999999999999999000123 '
- __bytes__() → bytes¶
- Return type
representation of this object as CSB43 records (using \n as separator)
- __init__(record: Optional[bytes] = None, **record_settings)¶
- Parameters
record (
basestring
or None) – csb recordstrict (
bool
) – treat warnings as exceptions when True
- Raises
- property padding¶
- property totalRecords¶
total number of entries
>>> c = ClosingFile() >>> c.totalRecords = 34 >>> c.totalRecords 34
Account – (es) Cuenta¶
- class csb43.csb43.Account(record: Optional[bytes] = None, **record_settings)¶
A Csb43 account / (es) Cuenta
Create an
Account
object from a CSB43 string record:>>> record = b'11000000000000000000000000000000110000000000000000 ' >>> a = Account(record)
From an empty object to a CSB43 string record:
>>> a = Account() >>> bytes(a) b'11 000000000000000000000000000000 '
- __bytes__() → bytes¶
- Return type
representation of this object as CSB43 records (using \n as separator)
- __init__(record: Optional[bytes] = None, **record_settings)¶
- Parameters
record (
basestring
or None) – csb record**record_settings – see
csb43.csb43.RecordSequence
- Raises
- __iter__() → Iterator[bytes]¶
- Return type
iterator of all the CSB43 records that this object represents
- property abstract: Optional[csb43.csb43.account.ClosingAccount]¶
- Return type
ClosingAccount
account abstract
- property accountNumber¶
account number / (es) numero de cuenta :rtype:
str
>>> a = Account() >>> a.accountNumber = '0000000000' >>> a.accountNumber '0000000000'
- add_exchange(record: Union[bytes, csb43.csb43.exchange.Exchange], update=False)¶
Add a new additional exchange record to the last added transaction
- Parameters
- Raises
See also
- add_item(record: Union[bytes, csb43.csb43.item.Item])¶
Add a new additional item record to the transaction
- Parameters
record (
Item
orbasestring
) – item record- Raises
csb43.utils.Csb43Exception
when the record is impossible to parse, or if the maximum number of complementary items has been reached
See also
- add_transaction(record: Union[bytes, csb43.csb43.transaction.Transaction])¶
Add a new transaction to the account
- Parameters
record (
Transaction
orbasestring
) – transaction record- Raises
- as_dict(decimal_fallback=None) → Dict[str, Any]¶
- Parameters
decimal_fallback – decimal number fallback representation
- Return type
a representation of this object as a
dict
. The keys will be localised
- property bankCode¶
bank code / (es) codigo de banco
- Return type
>>> a = Account() >>> a.bankCode = '0000' >>> a.bankCode '0000'
- property branchCode¶
branch code / (es) codigo de sucursal u oficina
- Return type
>>> a = Account() >>> a.branchCode = '0000' >>> a.branchCode '0000'
- close_account(record: Optional[Union[bytes, csb43.csb43.account.ClosingAccount]] = None, update=False)¶
Close the current account and generate an abstract object
- Parameters
record (
bool
) – csb recordupdate – update the abstract if already present
- Raises
csb43.utils.Csb43Exception
if invalid record or incongruent abstract
- property currency¶
currency object / (es) objecto de divisa
- Return type
pycountry.db.Currency
ISO 4217 codes can be assigned:
>>> a = Account() >>> a.currency = 'USD' >>> a.currency.alpha_3 'USD' >>> a.currency.numeric '840' >>> a.currency = '978' >>> a.currency.alpha_3 'EUR'
- property finalDate¶
- End date of the period to which the information corresponds /
(es) fecha de fin del periodo al que corresponde la informacion
- Return type
Setting a date:
>>> from datetime import date >>> a = Account() >>> a.finalDate = date(year=2012,month=2,day=13) >>> a.finalDate datetime.date(2012, 2, 13)
- get_account_key() → str¶
- Return type
int
two-digits checksum for the bank account / (es) digitos de control
- get_last_transaction() → csb43.csb43.transaction.Transaction¶
- Return type
the last added
Transaction
- property initialBalance¶
initial balance amount / (es) montante del balance inicial
Quantities can be assigned as numbers or strings, and they will be truncated to adjust the decimal format set for the object:
>>> a = Account() >>> a.initialBalance = 123 >>> a.initialBalance Decimal('123') >>> a.initialBalance = 123.45 >>> a.initialBalance Decimal('123.45') >>> a.initialBalance = '1234.56' >>> a.initialBalance Decimal('1234.56') >>> a.initialBalance = 1.2345 >>> a.initialBalance Decimal('1.23')
- property initialDate¶
- Start date of the period to which the information corresponds /
(es) fecha de comienzo del periodo al que corresponde la informacion
- Return type
Setting a date:
>>> from datetime import date >>> a = Account() >>> a.initialDate = date(year=2012,month=2,day=13) >>> a.initialDate datetime.date(2012, 2, 13)
- property padding¶
- property shortName¶
abbreviated name of the client / (es) nombre abreviado del cliente
- Return type
- class csb43.csb43.ClosingAccount(record: Optional[bytes] = None, **record_settings)¶
An Account abstact, given by a termination record
- property accountNumber¶
account number / (es) numero de cuenta
- property balance¶
final balance / (es) balance final
- property bankCode¶
bank code / (es) codigo de banco
- property branchCode¶
branch code / (es) codigo de sucursal u oficina
- property currency¶
currency object (
pycountry.db.Currency
) / (es) objecto de divisa
- property expense¶
total debit amounts / (es) montante total en el debe
- property expenseEntries¶
number of debit entries / (es) numero de entradas en el debe
- property income¶
total credit amounts / (es) montante total en el haber
- property incomeEntries¶
number of credit entries / (es) numero de entradas en el haber
- property padding¶
Transaction – (es) Movimiento¶
- class csb43.csb43.Transaction(record: Optional[bytes] = None, informationMode=3, **record_settings)¶
A Csb43 transaction / (es) Movimiento
Create a
Transaction
object from a CSB43 string record:>>> from csb43.csb43 import Transaction >>> record = b'22 0000000000000000000002000000000123450000000000000000000000 ' >>> t = Transaction(record)
From an empty object to a CSB43 string record:
>>> t = Transaction() >>> t.amount = 123.45 >>> bytes(t) b'22 0000000000000000000002000000000123450000000000000000000000 '
- __bytes__() → bytes¶
- Return type
representation of this object as CSB43 records (using \n as separator)
>>> bytes(t) b'22 000000000012021300000200000000123456000000000001234567890\ 0 something\n2301first item recor\ d \n2302\ second item recor\ d \n2401840000000\ 00012300 '
- __init__(record: Optional[bytes] = None, informationMode=3, **record_settings)¶
- Parameters
record (
basestring
or None) – csb recordinformationMode (
int
) – define mode used for transaction parsing, mostly for reference checksum**record_settings – see
csb43.csb43.RecordSequence
- Raises
- __iter__() → Iterator[bytes]¶
- Return type
iterator of all the CSB43 records that this object represents
>>> [x for x in t] ['22 0000000000120213000002000000001234560000000000012345678900 something', '2301first item record ', '2302second item record ', '240184000000000012300 ']
- add_exchange(record: Union[bytes, csb43.csb43.exchange.Exchange], update=False)¶
Add a new additional exchange record to the transaction
- Parameters
- Raises
Add an exchange object from a CSB43 string record:
>>> t = Transaction() >>> record = '{: <80}'.format('240197800000000012345') >>> t.add_exchange(record) >>> str(t.exchange) '240197800000000012345 '
Add an exchange object from a
Exchange
:>>> from csb43.csb43 import Exchange >>> t = Transaction() >>> e = Exchange() >>> e.amount = 123.45 >>> e.sourceCurrency = 'EUR' >>> t.add_exchange(e) >>> str(t.exchange) '240197800000000012345 '
- add_item(record: Union[bytes, csb43.csb43.item.Item])¶
Add a new optional item to the transaction.
- Parameters
record (
Item
orbasestring
) – item record- Raises
csb43.utils.Csb43Exception
when the record is impossible to parse, or if the maximum number of complementary items has been reached
- property amount¶
amount of the transaction / (es) cantidad implicada en el movimiento
- Return type
Decimal
Quantities can be assigned as numbers or strings, and they will be truncated to adjust the decimal format set for the object:
>>> t = Transaction() >>> t.amount = 123 >>> t.amount Decimal('123') >>> t.amount = 123.45 >>> t.amount Decimal('123.45') >>> t.amount = '1234.56' >>> t.amount Decimal('1234.56') >>> t.amount = 1.2345 >>> t.amount Decimal('1.23')
- as_dict(decimal_fallback=None) → Dict[str, Any]¶
- Parameters
decimal_fallback – decimal number fallback representation
- Return type
a representation of this object as a
dict
. The keys will be localised
>>> t = Transaction() >>> t.amount = '123.45' >>> t.as_dict() {u'cantidad': Decimal('123.45'), u'primera_referencia': None, u'segunda_referencia': None, u'concepto_propio': None, u'fecha_de_operacion': None, u'numero_del_documento': None, u'codigo_de_sucursal': None, u'concepto_comun': None, u'fecha_valor': None}
- property branchCode¶
branch code / (es) código de sucursal u oficina
- Return type
>>> t = Transaction() >>> t.branchCode = '0000' >>> t.branchCode '0000'
- property documentNumber¶
document number / (es) número del documento
- Return type
>>> t = Transaction() >>> t.documentNumber = 1 >>> t.documentNumber 1
- property optionalItems¶
list of optional items / (es) lista de conceptos adicionales
- property ownItem¶
own item (given by each bank to its transactions) / (es) concepto propio del banco
- Return type
>>> t = Transaction() >>> t.ownItem = 123 >>> t.ownItem '123' >>> t.ownItem = '125' >>> t.ownItem '125'
- property reference1¶
first reference (checksummed) / (es) primera referencia (verificada)
When using the information mode 3, the field is checksummed.
- Return type
>>> t = Transaction() >>> t.informationMode = 3 >>> t.reference1 = '012345678900' >>> t.reference1 '012345678900' >>> from csb43.utils import Csb43Exception >>> try: ... t.reference1 = '012345678901' ... except Csb43Exception as e: ... print(e) ... Validación fallida para el campo de referencia '012345678901'
- property reference2¶
second reference (not checksummed) / (es) segunda referencia (no verificada)
- Return type
>>> t = Transaction() >>> t.reference2 = '{: >16}'.format('something') >>> t.reference2 ' something'
inter-bank shared item / (es) concepto común
- Return type
>>> t = Transaction() >>> t.sharedItem = 12 >>> t.sharedItem '12' >>> t.sharedItem = '04' >>> t.sharedItem '04' >>> from csb43 import utils >>> utils.CONCEPTOS[t.sharedItem] 'GIROS - TRANSFERENCIAS - TRASPASOS - CHEQUES'
- property transactionDate¶
transaction date / (es) fecha de la operación
- Return type
Setting a date:
>>> from datetime import date >>> t = Transaction() >>> t.transactionDate = date(year=2012,month=2,day=13) >>> t.transactionDate datetime.date(2012, 2, 13)
- property valueDate¶
value date / (es) fecha valor
- Return type
Setting a date:
>>> from datetime import date >>> t = Transaction() >>> t.valueDate = date(year=2012,month=2,day=13) >>> t.valueDate datetime.date(2012, 2, 13)
Item – (es) Concepto¶
- class csb43.csb43.Item(record: Optional[bytes] = None, **record_settings)¶
Complementary item / (es) Concepto adicional (registro 23)
Create an
Item
object from a CSB43 string record:>>> from csb43.csb43 import Item >>> record = '2301primer concepto adicional segundo concepto adicional ' >>> i = Item(record) >>> i.item1 'primer concepto adicional' >>> i.item2 'segundo concepto adicional' >>> i.recordCode 1
From an empty object to a CSB43 string record:
>>> i = Item() >>> i.item1 = 'primer concepto adicional' >>> i.item2 = 'segundo concepto adicional' >>> i.recordCode = 1 >>> str(i) '2301primer concepto adicional segundo concepto adicional '
- __init__(record: Optional[bytes] = None, **record_settings)¶
- Parameters
record (
basestring
or None) – csb record**record_settings – see
csb43.csb43.RecordSequence
- Raises
- as_dict(decimal_fallback=None) → Dict[str, Any]¶
- Parameters
decimal_fallback – decimal number fallback representation
- Return type
a representation of this object as a
dict
. The keys will be localised
>>> i = Item() >>> i.as_dict() {u'concepto1': 'primer concepto adicional', u'concepto2': 'segundo concepto adicional', u'codigo_de_registro': 1}
- property item1¶
first additional item / (es) primer concepto adicional
- property item2¶
second additional item / (es) segundo concepto adicional
- property recordCode¶
code of record / (es) codigo de registro
Code can be assigned as a number or as a string:
>>> i = Item() >>> i.recordCode = 1 >>> i.recordCode 1 >>> i.recordCode = '2' >>> i.recordCode 2 >>> i.recordCode = '01' >>> i.recordCode 1 >>> try: ... i.recordCode = 10 ... except Exception as e: ... print(e) ... mal formato: el contenido b'10' no concuerda con el formato esperado rb'^0[12345]$' para este campo
Exchange – (es) Cambio de divisa¶
- class csb43.csb43.Exchange(record: Optional[bytes] = None, **record_settings)¶
Exchange record / (es) registro de cambio de divisa (24)
- __init__(record: Optional[bytes] = None, **record_settings)¶
- Parameters
record (
basestring
or None) – csb record**record_settings – see
csb43.csb43.RecordSequence
- Raises
Create an
Exchange
object from a CSB43 string record:>>> record = '{: <80}'.format('240197800000000012345') >>> e = Exchange(record) >>> print(e.amount) 123.45 >>> print(e.sourceCurrency.alpha_3) EUR >>> print(e.sourceCurrency.numeric) 978
From an empty object to a CSB43 string record:
>>> from csb43.csb43 import Exchange >>> e = Exchange() >>> e.amount = 123.45 >>> e.sourceCurrency = 'EUR' >>> bytes(e) b'240197800000000012345 '
- property amount¶
amount in the original currency / (es) cantidad en la divisa original
Quantities can be assigned as numbers or strings, and they will be truncated to adjust the decimal format set for the object:
>>> e = Exchange() >>> e.amount = 123 >>> e.amount Decimal('123') >>> e.amount = 123.45 >>> e.amount Decimal('123.45') >>> e.amount = '1234.56' >>> e.amount Decimal('1234.56') >>> e.amount = 1.2345 >>> e.amount Decimal('1.23')
- as_dict(decimal_fallback=None) → Dict[str, Any]¶
- Parameters
decimal_fallback – decimal number fallback representation
- Return type
a representation of this object as a
dict
. The keys will be localised
>>> e = Exchange() >>> e.sourceCurrency = "EUR" >>> e.amount = 1.23 >>> e.as_dict() {'divisa_original': 'EUR', 'cantidad': Decimal('1.23')}
- property padding¶
- property sourceCurrency¶
original currency / (es) divisa original
ISO 4217 codes can be assigned:
>>> e = Exchange() >>> e.sourceCurrency = 'USD' >>> e.sourceCurrency.alpha_3 'USD' >>> e.sourceCurrency.numeric '840' >>> e.sourceCurrency = '978' >>> e.sourceCurrency.alpha_3 'EUR'
As well as a
pycountry.db.Currency
object:>>> import pycountry >>> e.sourceCurrency = pycountry.currencies.get(alpha_3='EUR') >>> e.sourceCurrency = pycountry.currencies.get(alpha_3='USD') >>> e.sourceCurrency.alpha_3 'USD' >>> type(e.sourceCurrency) <class 'pycountry.db.Currency'>