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:
- (https://empresas.bankinter.com/www2/empresas/es/inicio/descarga/formato_de_ficheros)
- (http://empresa.lacaixa.es/deployedfiles/empreses/Estaticos/PDF/TransferenciaFicheros/Q43euro.pdf)
- (http://www.tesoreria.com/oldweb/index.php?option=com_content&view=article&id=128:la-norma-43-del-consejo-superior-bancario-csb&catid=59:normativa-nacional-e-internacional&Itemid=90)
File – (es) Fichero¶
-
class
csb43.csb43.
File
(fd=None, **record_settings)¶ A CSB43 file
Create a
File
object from a file descriptor:>>> from csb43.csb43 import File >>> with open("csb_file.csb") as fd: ... f = File(fd) ... # do something with f ...
Create an empty
File
object:>>> f = File()
-
__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=None, **record_settings)¶ Parameters: - fd (
file
) – a csb file - **record_settings – see
csb43.csb43.RecordSequence
Raises: - fd (
-
__iter__
()¶ 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 ... 11 000000000000000000000000000000 22 0000000000000000000001000000000000000000000000000000000000 88999999999999999999000002 >>>
-
abstract
¶ Return type: ClosingFile
file abstract
-
add_account
(record)¶ Add a new account
Parameters: record ( Account
orbasestring
) – account recordRaises: 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 recordRaises: csb43.utils.Csb43Exception
when the record is impossible to parse, or if the maximum number of complementary items has been reachedSee also
-
add_transaction
(record)¶ Add a new transaction to the last added account
Parameters: record ( Transaction
orbasestring
) – transaction recordRaises: csb43.utils.Csb43Exception
See also
-
as_dict
()¶ 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 recordRaises: csb43.utils.Csb43Exception
if record is not validSee also
-
close_file
(record=None)¶ Close the file with a termination record
Parameters: record ( ClosingFile
orbasestring
) – csb recordRaises: csb43.utils.Csb43Exception
if record is not validIf record is None, a new abstract is generated:
>>> c = csb.File() >>> c.is_closed() False >>> c.close_file() >>> c.is_closed() True >>> c.abstract.totalRecords 0 >>> c.add_account(csb.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:
>>> cf = csb.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 >>>
-
is_closed
()¶ Return type: True if this File has been properly closed
-
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=None, **record_settings)¶ A File abstract, given by a termination record
Create a
ClosingFile
object from a CSB43 string record:>>> from csb43.csb43 import ClosingFile >>> c = ClosingFile(record)
From an empty object to a CSB43 string record:
>>> c = ClosingFile() >>> c.totalRecords = 123 >>> str(c) '88999999999999999999000123 '
-
__bytes__
()¶ Return type: representation of this object as CSB43 records (using \n as separator)
-
__init__
(record=None, **record_settings)¶ Parameters: - record (
basestring
or None) – csb record - strict (
bool
) – treat warnings as exceptions when True
Raises: - record (
-
padding
¶
-
totalRecords
¶ total number of entries
>>> c.totalRecords = 34 >>> c.totalRecords 34 >>> c.totalRecords = '115' >>> c.totalRecords 115
-
Account – (es) Cuenta¶
-
class
csb43.csb43.
Account
(record=None, **record_settings)¶ A Csb43 account / (es) Cuenta
Create an
Account
object from a CSB43 string record:>>> from csb43.csb43 import Account >>> a = Account(record)
From an empty object to a CSB43 string record:
>>> a = Account() >>> str(a) '11 000000000000000000000000000000 '
-
__bytes__
()¶ Return type: representation of this object as CSB43 records (using \n as separator)
-
__init__
(record=None, **record_settings)¶ Parameters: - record (
basestring
or None) – csb record - **record_settings – see
csb43.csb43.RecordSequence
Raises: - record (
-
__iter__
()¶ Return type: iterator of all the CSB43 records that this object represents
-
abstract
¶ Return type: ClosingAccount
account abstract
-
accountNumber
¶ account number / (es) numero de cuenta :rtype:
str
>>> a.accountNumber = '0000000000' >>> a.accountNumber b'0000000000'
-
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 transaction
Parameters: record ( Item
orbasestring
) – item recordRaises: csb43.utils.Csb43Exception
when the record is impossible to parse, or if the maximum number of complementary items has been reachedSee also
-
add_transaction
(record)¶ Add a new transaction to the account
Parameters: record ( Transaction
orbasestring
) – transaction recordRaises: csb43.utils.Csb43Exception
-
bankCode
¶ bank code / (es) codigo de banco
Return type: str
>>> a.bankCode = '0000' >>> a.bankCode b'0000'
-
branchCode
¶ branch code / (es) codigo de sucursal u oficina
Return type: str
>>> a.branchCode = '0000' >>> a.branchCode b'0000'
-
close_account
(record=None, update=False)¶ Close the current account and generate an abstract object
Parameters: - record (
bool
) – csb record - update – update the abstract if already present
Raises: csb43.utils.Csb43Exception
if invalid record or incongruent abstract- record (
-
currency
¶ currency object / (es) objecto de divisa
Return type: pycountry.db.Currency
ISO 4217 codes can be assigned:
>>> a.currency = 'USD' >>> a.currency.alpha_3 u'USD' >>> a.currency.numeric u'840' >>> a.currency = '978' >>> a.currency.alpha_3 u'EUR'
-
finalDate
¶ - End date of the period to which the information corresponds /
- (es) fecha de fin del periodo al que corresponde la informacion
Return type: datetime.datetime
Setting a date:
>>> a.finalDate = datetime.datetime(year=2012,month=2,day=13).date() >>> a.finalDate datetime.datetime(2012, 2, 13, 0, 0)
-
get_account_key
()¶ Return type: int
two-digits checksum for the bank account / (es) digitos de control
-
get_last_transaction
()¶ Return type: the last added Transaction
-
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.initialBalance = 123 >>> a.initialBalance 123.0 >>> a.initialBalance = 123.45 >>> a.initialBalance 123.45 >>> a.initialBalance = '1234.56' >>> a.initialBalance 1234.56 >>> a.initialBalance = 1.2345 >>> a.initialBalance 1.23
-
initialDate
¶ - Start date of the period to which the information corresponds /
- (es) fecha de comienzo del periodo al que corresponde la informacion
Return type: datetime.datetime
Setting a date:
>>> a.initialDate = datetime.datetime(year=2012,month=2,day=13).date() >>> a.initialDate datetime.datetime(2012, 2, 13, 0, 0)
-
padding
¶
-
class
csb43.csb43.
ClosingAccount
(record=None, **record_settings)¶ An Account abstact, given by a termination record
-
__init__
(record=None, **record_settings)¶ Parameters: Raises:
-
accountNumber
¶ account number / (es) numero de cuenta
-
balance
¶ final balance / (es) balance final
-
bankCode
¶ bank code / (es) codigo de banco
-
branchCode
¶ branch code / (es) codigo de sucursal u oficina
-
currency
¶ currency object (
pycountry.db.Currency
) / (es) objecto de divisa
-
expense
¶ total debit amounts / (es) montante total en el debe
-
expenseEntries
¶ number of debit entries / (es) numero de entradas en el debe
-
income
¶ total credit amounts / (es) montante total en el haber
-
incomeEntries
¶ number of credit entries / (es) numero de entradas en el haber
-
padding
¶
-
Transaction – (es) Movimiento¶
-
class
csb43.csb43.
Transaction
(record=None, informationMode=3, **record_settings)¶ A Csb43 transaction / (es) Movimiento
Create a
Transaction
object from a CSB43 string record:>>> from csb43.csb43 import Transaction >>> t = Transaction(record)
From an empty object to a CSB43 string record:
>>> t = Transaction() >>> t.amount = 123.45 >>> str(t) '22 0000000000000000000002000000000123450000000000000000000000 '
-
__bytes__
()¶ Return type: representation of this object as CSB43 records (using \n as separator) >>> str(t) '22 000000000012021300000200000000123456000000000001234567890\ 0 something\n2301first item recor\ d \n2302\ second item recor\ d \n2401840000000\ 00012300 '
-
__init__
(record=None, informationMode=3, **record_settings)¶ Parameters: - record (
basestring
or None) – csb record - informationMode (
int
) – define mode used for transaction parsing, mostly for reference checksum - **record_settings – see
csb43.csb43.RecordSequence
Raises: - record (
-
__iter__
()¶ 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, update=False)¶ Add a new additional exchange record to the transaction
Parameters: Raises: Add an exchange object from a CSB43 string record:
>>> from csb43.csb43 import Exchange >>> record = '{: <80}'.format('240197800000000012345') >>> t.add_exchange(record) >>> str(t.exchange) '240197800000000012345 '
Add an exchange object from a
Exchange
:>>> from csb43.csb43 import Exchange >>> e = Exchange() >>> e.amount = 123.45 >>> e.sourceCurrency = 'EUR' >>> t.add_exchange(e) >>> str(t.exchange) '240197800000000012345 '
-
add_item
(record)¶ Add a new optional item to the transaction.
Parameters: record ( Item
orbasestring
) – item recordRaises: csb43.utils.Csb43Exception
when the record is impossible to parse, or if the maximum number of complementary items has been reached
-
amount
¶ amount of the transaction / (es) cantidad implicada en el movimiento
Return type: float
Quantities can be assigned as numbers or strings, and they will be truncated to adjust the decimal format set for the object:
>>> t.amount = 123 >>> t.amount 123.0 >>> t.amount = 123.45 >>> t.amount 123.45 >>> t.amount = '1234.56' >>> t.amount 1234.56 >>> t.amount = 1.2345 >>> t.amount 1.23
-
as_dict
()¶ Return type: a representation of this object as a dict
. The keys will be localised>>> t.as_dict() {u'cantidad': 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}
-
branchCode
¶ branch code / (es) código de sucursal u oficina
Return type: str
>>> t.branchCode = '0000' >>> t.branchCode '0000'
-
documentNumber
¶ document number / (es) número del documento
Return type: int
>>> t.documentNumber = 1 >>> t.documentNumber 1
-
optionalItems
¶ list of optional items / (es) lista de conceptos adicionales
Return type: list
ofItem
attached to this transaction
-
ownItem
¶ own item (given by each bank to its transactions) / (es) concepto propio del banco
Return type: str
>>> t.ownItem = 123 >>> t.ownItem '123' >>> t.ownItem = '125' >>> t.ownItem '125'
-
reference1
¶ first reference (checksummed) / (es) primera referencia (verificada)
When using the information mode 3, the field is checksummed.
Return type: str
>>> t.informationMode = 3 >>> t.reference1 = '012345678900' >>> t.reference1 '012345678900' >>> try: ... t.reference1 = '012345678901' ... except Exception, e: ... print e ... Validación fallida para el campo de referencia '012345678901'
-
reference2
¶ second reference (not checksummed) / (es) segunda referencia (no verificada)
Return type: str
>>> t.reference2 = '{: >16}'.format('something') >>> t.reference2 ' something'
inter-bank shared item / (es) concepto común
Return type: str
>>> t.sharedItem = 12 >>> t.sharedItem '12' >>> t.sharedItem = '04' >>> t.sharedItem '04' >>> from csb43.csb43 import utils >>> utils.CONCEPTOS[t.sharedItem] 'GIROS - TRANSFERENCIAS - TRASPASOS - CHEQUES'
-
transactionDate
¶ transaction date / (es) fecha de la operación
Return type: datetime.datetime
Setting a date:
>>> t.transactionDate = datetime.datetime(year=2012,month=2,day=13).date() >>> t.transactionDate datetime.datetime(2012, 2, 13, 0, 0)
-
valueDate
¶ value date / (es) fecha valor
Return type: datetime.datetime
Setting a date:
>>> t.valueDate = datetime.datetime(year=2012,month=2,day=13).date() >>> t.valueDate datetime.datetime(2012, 2, 13, 0, 0)
Item – (es) Concepto¶
-
class
csb43.csb43.
Item
(record=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 '
-
__bytes__
()¶ Return type: representation of this object as a CSB43 record
-
__init__
(record=None, **record_settings)¶ Parameters: - record (
basestring
or None) – csb record - **record_settings – see
csb43.csb43.RecordSequence
Raises: - record (
-
as_dict
()¶ Return type: a representation of this object as a dict
. The keys will be localised>>> i.as_dict() {u'concepto1': 'primer concepto adicional', u'concepto2': 'segundo concepto adicional', u'codigo_de_registro': 1}
-
item1
¶ first additional item / (es) primer concepto adicional
-
item2
¶ second additional item / (es) segundo concepto adicional
-
recordCode
¶ code of record / (es) codigo de registro
Code can be assigned as a number or as a string:
>>> i.recordCode = 1 >>> i.recordCode 1 >>> i.recordCode = '2' >>> i.recordCode 2 >>> i.recordCode = '01' >>> i.recordCode 1 >>> try: ... i.recordCode = 10 ... except Exception, e: ... print e ... mal formato: el contenido '10' no concuerda con el formato esperado r'^0[12345]$' para este campo
Exchange – (es) Cambio de divisa¶
-
class
csb43.csb43.
Exchange
(record=None, **record_settings)¶ Exchange record / (es) registro de cambio de divisa (24)
-
__bytes__
()¶ Return type: representation of this object as a CSB43 record
-
__init__
(record=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:>>> from csb43.csb43 import Exchange >>> 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' >>> print e 240197800000000012345
- record (
-
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.amount = 123 >>> e.amount 123.0 >>> e.amount = 123.45 >>> e.amount 123.45 >>> e.amount = '1234.56' >>> e.amount 1234.56 >>> e.amount = 1.2345 >>> e.amount 1.23
-
as_dict
()¶ Return type: a representation of this object as a dict
. The keys will be localised>>> e.as_dict() {u'divisa_original': 'EUR', u'cantidad': 1.23}
-
padding
¶
-
sourceCurrency
¶ original currency / (es) divisa original
ISO 4217 codes can be assigned:
>>> e.sourceCurrency = 'USD' >>> e.sourceCurrency.alpha_3 u'USD' >>> e.sourceCurrency.numeric u'840' >>> e.sourceCurrency = '978' >>> e.sourceCurrency.alpha_3 u'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 u'USD' >>> type(e.sourceCurrency) <class 'pycountry.db.Currency'>
-