MambuPy.api.entities

Mambu Entities

Classes

MambuEntity(**kwargs)

A Mambu object that you may work with directly on Mambu web too.

MambuEntityAttachable([cf_class])

A Mambu object with attaching capabilities.

MambuEntityCF(value[, path, typecf, mcf])

A Mambu CustomField obtained via an Entity.

MambuEntityCommentable([cf_class])

A Mambu object with commenting capabilities.

MambuEntityOwnable([cf_class])

An entity which allows to be 'owned' by another.

MambuEntitySearchable([cf_class])

A Mambu object with searching capabilities.

MambuEntityWritable([cf_class])

A Mambu object with writing capabilities.

MambuInstallment([cf_class])

Loan Account Installment (aka Repayment)

class MambuPy.api.entities.MambuEntity(**kwargs)[source]

Bases: MambuStruct

A Mambu object that you may work with directly on Mambu web too.

classmethod __build_object(connector, resp, attrs, tzattrs, get_entities=False, detailsLevel='BASIC', debug=False)

Builds an instance of an Entity object

Parameters:
  • cls (obj) – the object to build

  • connector (obj) – connector object to Mambu

  • resp (bytes) – the raw json that originates the object

  • attrs (dict) – the dict with the values to build the object

  • tzattrs (dict) – the dict with TZ data for datetimes in attrs

  • get_entities (bool) – should MambuPy automatically instantiate other MambuPy entities found inside the built entity?

  • detailsLevel (str) – “BASIC” or “FULL”

  • debug (bool) – print debugging info

classmethod __get_several_args(args, get_entities=False, debug=False)

Processes MambuPy.api.entities.get_several arguments.

Parameters:
  • cls (obj) – the object for which the args are built

  • args (dict) – optional arguments received by get_several method

__init__(**kwargs)[source]
__module__ = 'MambuPy.api.entities'
__search_field_in_cfsets(field)

Search for a field in custom field sets for the entity.

Retrieves all the customfieldsets for this entity and looks if the field lives there.

If field is found, returns the path going through the set.

Parameters:

field (str) – the field to search in customfieldsets

Returns:

(str) – the path for the field when found or None if not found.

_connector = None

Default connector (REST)

_extract_field_path(field, attrs_dict={}, original_keys=[], cf_class=None)[source]

Extracts the path for a given field.

If the field is a Custom Field, the path is given in a property in its attrs dict. (cf MambuPy.api.entities.MambuEntityCF)

If not, first it looks at the original keys in attrs to look if it lives in the root (/) of the entity.

If not, looks for the field in the custom field sets of the entity.

If not, the path does not exists, but it may be a valid path, default to / . Here we are hoping the path is correct, otherwise a PATCH may throw an error.

TODO: perhaps here, in the default case, a better approach would be to implement, and maintain, the schema for each entity as a VO, and validate if field belongs here. If not, default would be an empty string for not being a valid field.

Parameters:
  • field (str) – a field for which to extract the path

  • attrs (dict) – an attrs structure holding the field

  • original_keys (list) – keys for entity original attrs

  • cf_class (obj) – the class used for custom field VOs. If the field is a CF in attrs, the path is a property of it. If not, it lives on the “root” of the attrs

Returns:

(str) – the path to the field.

_filter_keys = []

allowed filters for get_all filtering

classmethod _get_several(get_func, connector, **kwargs)[source]

get several entities.

Using certain mambu connector function and its particular arguments.

arg limit has a hard limit imposed by Mambu, that only 1,000 registers can be retrieved, so a pagination must be done to retrieve more registries.

A pagination algorithm (using the offset and the 1,000 limitation) is applied here so that limit may be higher than 1,000 and _get_several will get a all the registers from Mambu in several requests.

Parameters:
  • get_func (function) – mambu request function that returns several entities (json [])

  • connector (obj) – connector object to Mambu

  • kwargs (dict) –

    keyword arguments to pass on to get_func as arguments

    • prefix (str): prefix for connections to Mambu

  • kwargs

    keyword arguments to pass on to get_func as params

    • detailsLevel (str): “BASIC” or “FULL”

    • offset (int): >= 0

    • limit (int): >= 0 If limit=0 or None, the algorithm will retrieve

      EVERYTHING according to the given filters, using several requests to that end.

  • kwargs

    keyword arguments for this method

    • get_entities (bool): should MambuPy automatically instantiate

      other MambuPy entities found inside the retrieved entities?

    • debug (bool): print debugging info

Returns:

list of instances of an entity with data from Mambu, assembled from possibly several calls to get_func

_prefix = ''

prefix constant for connections to Mambu

_sortBy_fields = []

allowed fields for get_all sorting

classmethod get(entid, detailsLevel='BASIC', get_entities=False, **kwargs)[source]

get, a single entity, identified by its entid.

Parameters:
  • entid (str) – ID for the entity

  • detailsLevel (str BASIC/FULL) – ask for extra details or not

  • get_entities (bool) – should MambuPy automatically instantiate other MambuPy entities found inside the retrieved entity?

  • kwargs (dict) –

    keyword arguments for this method.

    May include a user, pwd and url to connect to Mambu.

    • debug (bool): print debugging info

Returns:

instance of an entity with data from Mambu

classmethod get_all(filters=None, offset=None, limit=None, paginationDetails='OFF', detailsLevel='BASIC', sortBy=None, **kwargs)[source]

get_all, several entities, filtering allowed

Parameters:
  • filters (dict) – key-value filters, dependes on each entity (keys must be one of the _filter_keys)

  • offset (int) – pagination, index to start searching

  • limit (int) – pagination, number of elements to retrieve

  • paginationDetails (str ON/OFF) – ask for details on pagination

  • detailsLevel (str BASIC/FULL) – ask for extra details or not

  • sortBy (str) – field1:ASC,field2:DESC, sorting criteria for results (fields must be one of the _sortBy_fields)

  • kwargs (dict) – extra parameters that a specific entity may receive in its get_all method. May include a user, pwd and url to connect to Mambu.

Returns:

list of instances of an entity with data from Mambu

refresh(detailsLevel='')[source]

get again this single entity, identified by its entid.

Updates _attrs with responded data. Loses any change on _attrs that overlaps with anything from Mambu. Leaves alone any other properties that don’t come in the response.

Parameters:

detailsLevel (str BASIC/FULL) – ask for extra details or not

class MambuPy.api.entities.MambuEntityAttachable(cf_class=<class 'MambuPy.api.classes.GenericClass'>, **kwargs)[source]

Bases: MambuStruct, MambuAttachable

A Mambu object with attaching capabilities.

__abstractmethods__ = frozenset({})
__module__ = 'MambuPy.api.entities'
_abc_impl = <_abc_data object>
_attachments = {}

dict of attachments of an entity, key is the id

_ownerType = ''

attachments owner type of this entity

attach_document(filename, title='', notes='')[source]

uploads an attachment to this entity

_attachments dicitionary gets a new entry with the attached document.

Parameters:
  • filename (str) – path and filename of file to upload as attachment

  • title (str) – name to assign to the attached file in Mambu

  • notes (str) – notes to associate to the attached file in Mambu

Returns:

Mambu’s response with metadata of the attached document

del_attachment(documentName=None, documentId=None)[source]

deletes an attachment by its documentName.

Parameters:
  • documentName (str) – optional, the name (title) of the document to be deleted

  • documentid (str) – optional, the id of the document to be deleted

Raises:

MambuPyError – if the documentId and the documentName is not an attachment of the entity

get_attachments_metadata(offset=None, limit=None, paginationDetails='OFF')[source]

Gets metadata for all the documents attached to an entity

_attachments dicitionary is cleaned and set with attached documents.

Parameters:
  • offset (int) – pagination, index to start searching

  • limit (int) – pagination, number of elements to retrieve

  • paginationDetails (str ON/OFF) – ask for details on pagination

Returns:

Mambu’s response with metadata of the attached documents

class MambuPy.api.entities.MambuEntityCF(value, path='', typecf='STANDARD', mcf=None)[source]

Bases: MambuValueObject

A Mambu CustomField obtained via an Entity.

This is NOT a CustomField obtained through it’s own endpoint, those go in another separate class.

Here you just have a class to manage custom field values living inside some Mambu entity.

__init__(value, path='', typecf='STANDARD', mcf=None)[source]
__module__ = 'MambuPy.api.entities'
get_mcf()[source]

Instance the MambuCustomField (MCF) of this entityCF.

The MCF is set in the mcf property of this object.

If this entityCF is a list, the mcf is set to a dictionary of field-MCFields.

class MambuPy.api.entities.MambuEntityCommentable(cf_class=<class 'MambuPy.api.classes.GenericClass'>, **kwargs)[source]

Bases: MambuStruct, MambuCommentable

A Mambu object with commenting capabilities.

__abstractmethods__ = frozenset({})
__module__ = 'MambuPy.api.entities'
_abc_impl = <_abc_data object>
_comments = []

list of comments of an entity

comment(comment)[source]

Comments this entity

_comments list gets a new entry with comment.

Parameters:

comment (str) – the text of the comment

Returns:

Mambu’s response with metadata of the posted comment

get_comments(offset=None, limit=None, paginationDetails='OFF')[source]

Gets comments for this entity

_comments list is cleaned and set with retrieved comments

Parameters:
  • offset (int) – pagination, index to start searching

  • limit (int) – pagination, number of elements to retrieve

  • paginationDetails (str ON/OFF) – ask for details on pagination

Returns:

Mambu’s response with retrieved comments

class MambuPy.api.entities.MambuEntityOwnable(cf_class=<class 'MambuPy.api.classes.GenericClass'>, **kwargs)[source]

Bases: MambuStruct, MambuOwnable

An entity which allows to be ‘owned’ by another.

An owned entity has an ‘accountHolderKey’ and ‘accountHolderType’ fields.

Because of that, you may call get_accountHolder on the owned entity to instantiate the MambuEntity who owns it.

__abstractmethods__ = frozenset({})
__module__ = 'MambuPy.api.entities'
_abc_impl = <_abc_data object>
_assignEntObjs(entities=None, detailsLevel='BASIC', get_entities=False, debug=False)[source]

Overwrites MambuPy.api.mambustruct._assignEntObjs for MambuLoan

Determines the type of account holder and instantiates accordingly

class MambuPy.api.entities.MambuEntitySearchable(cf_class=<class 'MambuPy.api.classes.GenericClass'>, **kwargs)[source]

Bases: MambuStruct, MambuSearchable

A Mambu object with searching capabilities.

__abstractmethods__ = frozenset({})
__module__ = 'MambuPy.api.entities'
_abc_impl = <_abc_data object>
classmethod search(filterCriteria=None, sortingCriteria=None, offset=None, limit=None, paginationDetails='OFF', detailsLevel='BASIC', **kwargs)[source]

search, several entities, filtering criteria allowed

Parameters:
  • filterCriteria (list of dicts) – fields according to each entity FilterCriteria schema

  • sortingCriteria (dict) – fields according to each entity SortingCriteria

  • offset (int) – pagination, index to start searching

  • limit (int) – pagination, number of elements to retrieve

  • paginationDetails (str ON/OFF) – ask for details on pagination

  • detailsLevel (str BASIC/FULL) – ask for extra details or not

Returns:

list of instances of an entity with data from Mambu

class MambuPy.api.entities.MambuEntityWritable(cf_class=<class 'MambuPy.api.classes.GenericClass'>, **kwargs)[source]

Bases: MambuStruct, MambuWritable

A Mambu object with writing capabilities.

__abstractmethods__ = frozenset({})
__module__ = 'MambuPy.api.entities'
__patch_field_op(field, original_attrs)

Returns a valid ADD or REPLACE operation tuple for a field in attrs.

__patch_op(operation, attrs, original_keys, field, cf_class)

Returns a patch operation tuple.

Parameters:
  • operation (str) – One of ADD, REPLACE or REMOVE (MOVE not supproted yet)

  • attrs (dict) – the attrs structure holding the field

  • original_keys (list) – original keys for the entity attrs

  • field (str) – the field for which to apply a patch operation

  • cf_class (obj) – the class used for custom field VOs

Returns:

(tuple) – according to the PATCH operation None: in case the field is not a valid attribute to patch

_abc_impl = <_abc_data object>
create()[source]

creates a mambu entity

Uses the current values of the _attrs to send to Mambu. Pre-requires that CustomFields are updated previously. Post-requires that CustomFields are extracted again.

patch(fields=None, autodetect_remove=False)[source]

patches a mambu entity

Allows patching of parts of the entity up to Mambu.

fields is a list of the keys in the _attrs that will be sent to Mambu

autodetect automatically searches for deleted fields and patches a remove in Mambu.

Pre-requires that CustomFields are updated previously. Post-requires that CustomFields are extracted again.

Parameters:
  • fields (list of str) – list of ids of fields to explicitly patch

  • autodetect_remove (bool) – False: if deleted fields, don’t remove them True: if delete field, remove them

Autodetect operation, for any field (every field if fields param is None):

  • ADD: in attrs, but not in resp

  • REPLACE: in attrs, and in resp

  • REMOVE: not in attrs, but in resp

  • MOVE: not yet implemented (how to autodetect? request needs ‘from’ element)

Raises:

MambuPyError – if field not in attrrs, and not in resp

update()[source]

updates a mambu entity

Uses the current values of the _attrs to send to Mambu. Pre-requires that CustomFields are updated previously. Post-requires that CustomFields are extracted again.

class MambuPy.api.entities.MambuInstallment(cf_class=<class 'MambuPy.api.classes.GenericClass'>, **kwargs)[source]

Bases: MambuStruct

Loan Account Installment (aka Repayment)

__module__ = 'MambuPy.api.entities'
__repr__()[source]

repr tells the class name, the number, the state and the dueDate