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) for storing bank account transactions.

(es) Herramientas para leer y validar datos almacenados siguiendo la norma 43 del Consejo Superior Bancario (CSB).

File – (es) Fichero

class csb43.csb43.File(fd=None, strict=True, decimal=2, yearFirst=True)

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()
    
__init__(fd=None, strict=True, decimal=2, yearFirst=True)
Parameters:
  • fd (file) – a csb file
  • strict (bool) – treat warnings as exceptions when True
  • decimal (int) – number of digits to be considered as the decimal part in money
  • yearFirst (bool) – switch between YYMMD [True] and DDMMYY [False] date formats
Raises :

csb43.utils.Csb43Exception

__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
>>>
__str__()
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
__weakref__

list of weak references to the object (if defined)

abstract
Return type:ClosingFile file abstract
accounts
Return type:list of accounts
add_account(record)

Add a new account

Parameters:record (Account or basestring) – 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:
  • record (Exchange or basestring) – csb exchange record or object
  • update (bool) – update the current exchange object if it exists
Raises :

csb43.utils.Csb43Exception

add_item(record)

Add a new additional item record to the last added transaction

Parameters:record (Item or basestring) – item record
Raises :csb43.utils.Csb43Exception when the record is impossible to parse, or if the maximum number of complementary items has been reached
add_transaction(record)

Add a new transaction to the last added account

Parameters:record (Transaction or basestring) – transaction record
Raises :csb43.utils.Csb43Exception
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 or basestring) – csb record
Raises :csb43.utils.Csb43Exception if record is not valid
close_file(record=None)

Close the file with a termination record

Parameters:record (ClosingFile or basestring) – csb record
Raises :csb43.utils.Csb43Exception if record is not valid

If 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
>>>
get_last_account()
Return type:the last added Account
is_closed()
Return type:True if this File has been properly closed
class csb43.csb43.ClosingFile(record=None, strict=True)

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                                                      '
__init__(record=None, strict=True)
Parameters:
  • record (basestring or None) – csb record
  • strict (bool) – treat warnings as exceptions when True
Raises :

csb43.utils.Csb43Exception

__str__()
Return type:representation of this object as CSB43 records (using \n as separator)
__weakref__

list of weak references to the object (if defined)

padding

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, strict=True, decimal=2, yearFirst=True)

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                              '
    
__init__(record=None, strict=True, decimal=2, yearFirst=True)
Parameters:
  • record (basestring or None) – csb record
  • strict (bool) – treat warnings as exceptions when True
  • decimal (int) – number of digits to be considered as the decimal part in money
  • yearFirst (bool) – switch between YYMMD [True] and DDMMYY [False] date formats
Raises :

csb43.utils.Csb43Exception

__iter__()
Return type:iterator of all the CSB43 records that this object represents
__str__()
Return type:representation of this object as CSB43 records (using \n as separator)
abstract
Return type:ClosingAccount account abstract
accountNumber

account number / (es) numero de cuenta

Return type:str
>>> a.accountNumber = '0000000000'
>>> a.accountNumber
'0000000000'
add_exchange(record, update=False)

Add a new additional exchange record to the last added transaction

Parameters:
  • record (Exchange or basestring) – csb exchange record or object
  • update (bool) – update the current exchange object if it exists
Raises :

csb43.utils.Csb43Exception

add_item(record)

Add a new additional item record to the transaction

Parameters:record (Item or basestring) – item record
Raises :csb43.utils.Csb43Exception when the record is impossible to parse, or if the maximum number of complementary items has been reached
add_transaction(record)

Add a new transaction to the account

Parameters:record (Transaction or basestring) – transaction record
Raises :csb43.utils.Csb43Exception
as_dict()
Return type:a representation of this object as a dict. The keys will be localised
bankCode

bank code / (es) codigo de banco

Return type:str
>>> a.bankCode = '0000'
>>> a.bankCode
'0000'
branchCode

branch code / (es) codigo de sucursal u oficina

Return type:str
>>> a.branchCode = '0000'
>>> a.branchCode
'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 of incongruent abstract

currency

currency object / (es) objecto de divisa

Return type:pycountry.db.Currency

ISO 4217 codes can be assigned:

>>> a.currency = 'USD'
>>> a.currency.letter
u'USD'
>>> a.currency.numeric
u'840'
>>> a.currency = '978'
>>> a.currency.letter
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
informationMode

information mode / (es) modalidad de informacion

>>> a.informationMode = 1
>>> a.informationMode
1
>>> a.informationMode = '2'
>>> a.informationMode
2
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)
is_closed()
Return type:bool True if this Account has been properly closed
padding

padding

shortName

abbreviated name of the client / (es) nombre abreviado del cliente

Return type:str
transactions

list of transactions / (es) lista de movimientos

class csb43.csb43.ClosingAccount(record=None, strict=True, decimal=2, yearFirst=True)

An Account abstact, given by a termination record

__init__(record=None, strict=True, decimal=2, yearFirst=True)
Parameters:
  • record (basestring or None) – csb record
  • strict (bool) – treat warnings as exceptions when True
  • decimal (int) – number of digits to be considered as the decimal part in money
  • yearFirst (bool) – switch between YYMMD [True] and DDMMYY [False] date formats
Raises :

csb43.utils.Csb43Exception

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

padding

Transaction – (es) Movimiento

class csb43.csb43.Transaction(record=None, strict=True, decimal=2, yearFirst=True)

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                '
    
__init__(record=None, strict=True, decimal=2, yearFirst=True)
Parameters:
  • record (basestring or None) – csb record
  • strict (bool) – treat warnings as exceptions when True
  • decimal (int) – number of digits to be considered as the decimal part in money
  • yearFirst (bool) – switch between YYMMD [True] and DDMMYY [False] date formats
Raises :

csb43.utils.Csb43Exception

__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                                                           ']
__str__()
Return type:representation of this object as CSB43 records (using \n as separator)
>>> str(t)
'22    0000000000120213000002000000001234560000000000012345678900       something\n2301first item record                                                           \n2302second item record                                                          \n240184000000000012300                                                           '
add_exchange(record, update=False)

Add a new additional exchange record to the transaction

Parameters:
  • record (Exchange or basestring) – csb exchange record or object
  • update (bool) – update the current exchange object if it exists
Raises :

csb43.utils.Csb43Exception

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 or basestring) – item record
Raises :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
exchange

exchange object / (es) objecto de cambio de divisa

Return type:Exchange
optionalItems

list of optional items / (es) lista de conceptos adicionales

Return type:list of Item 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'
padding

padding

reference1

first reference (checksummed) / (es) primera referencia (verificada)

Return type:str
>>> 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'
sharedItem

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, strict=True)

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=None, strict=True)
Parameters:
  • record (basestring or None) – csb record
  • strict (bool) – treat warnings as exceptions when True
Raises :

csb43.utils.Csb43Exception

__str__()
Return type:representation of this object as a CSB43 record
__weakref__

list of weak references to the object (if defined)

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, strict=True, decimal=2)

Exchange record / (es) registro de cambio de divisa (24)

__init__(record=None, strict=True, decimal=2)
Parameters:
  • record (basestring or None) – csb record
  • strict (bool) – treat warnings as exceptions when True
  • decimal (int) – number of digits to be considered as the decimal part in money
Raises :

csb43.utils.Csb43Exception

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.letter
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
__str__()
Return type:representation of this object as a CSB43 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

padding

sourceCurrency

original currency / (es) divisa original

ISO 4217 codes can be assigned:

>>> e.sourceCurrency = 'USD'
>>> e.sourceCurrency.letter
u'USD'
>>> e.sourceCurrency.numeric
u'840'
>>> e.sourceCurrency = '978'
>>> e.sourceCurrency.letter
u'EUR'

As well as a pycountry.db.Currency object:

>>> import pycountry
>>> e.sourceCurrency = pycountry.currencies.get(letter='EUR')
>>> e.sourceCurrency = pycountry.currencies.get(letter='USD')
>>> e.sourceCurrency.letter
u'USD'
>>> type(e.sourceCurrency)
<class 'pycountry.db.Currency'>

Others

csb43.csb43.showInfo(csb, fd=<open file '<stderr>', mode 'w' at 0x7f1edf56f270>)
Parameters:
  • csb (File) – csb file object
  • fd (file) – file descriptor