This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
MambuPy is a Python library for interacting with Mambu (a cloud lending platform). The library supports two distinct approaches:
- REST API Integration - Primary interface using Mambu's REST API (v1 and v2)
- ORM Interface - Direct database access using SQLAlchemy for DB backups
The project is currently at version 2.1.0 and supports Python 3.7+.
MambuPy maintains two separate REST API implementations:
-
MambuPy.api.*- Modern API v2 implementation (actively developed)- Located in
MambuPy/api/ - Uses
MambuConnectorRESTfor HTTP communication - Implements entities as
MambuEntitysubclasses with mixins (Writable, Searchable, Attachable, Commentable, Ownable) - Session management via
SessionSingletonpattern for connection reuse
- Located in
-
MambuPy.rest.*- Legacy API v1 implementation (deprecated but maintained)- Located in
MambuPy/rest/ - Older REST implementation using
MambuStructbase class - Kept for backward compatibility
- Located in
-
mambuconfig.py- Configuration management supporting:- RC files (
~/.mambupy.rc,/etc/mambupy.rc) - Environment variables (
MAMBUPY_*) - Command-line arguments (
mambupy_*)
- RC files (
-
mambugeturl.py- URL construction for Mambu REST endpoints -
mambuutil.py- Utility functions, error classes, and constants -
MambuPy/api/connector/- REST connector implementationsrest.py- Main REST connector with retry logic and session managementmambuconnector.py- Base connector classes (Reader/Writer)
-
MambuPy/api/entities.py- Base entity classes and custom field handling -
MambuPy/api/interfaces.py- ABC interfaces for entity capabilities -
MambuPy/orm/- SQLAlchemy schemas for database access (optional, requiresfulldependencies)
Custom fields (_customFields) are extracted into separate CF objects during entity instantiation. They're stored in a dedicated structure and must be explicitly updated before write operations (update/create/patch).
Datetime fields lose timezone info when converted to Python datetimes. TZ information is preserved separately in the _tzattrs dictionary, allowing TZ-naive datetime comparisons in user code.
Run all tests:
make testRun tests without API v2 tests:
make test APIV2=noRun a single test:
coverage run --append --rcfile=./.coveragerc tests/unit_mambuconfig.pyRun API v2 specific tests:
coverage run --append --rcfile=./.coveragerc tests/api/unit_mambuloan.pyRun legacy linter (pylint):
make lintRun modern linters (ruff, black, isort):
make lint2Auto-fix linting issues:
make lint2-fixBuild the package:
python -m buildGenerate documentation:
cd docs && make htmlMambuPy requires configuration to connect to Mambu. Priority order (highest to lowest):
- Command-line arguments:
--mambupy_apiurl,--mambupy_apiuser,--mambupy_apipwd - Environment variables:
MAMBUPY_APIURL,MAMBUPY_APIUSER,MAMBUPY_APIPWD - RC files:
~/.mambupy.rcor/etc/mambupy.rc
RC file format:
[API]
apiurl=https://your-domain.mambu.com
apiuser=your_api_user
apipwd=your_api_password
apipagination=50
activate_request_session_objects=True
[DB]
dbname=database_name
dbuser=db_user
dbpwd=db_password
dbhost=db_host
dbport=3306
dbeng=mysql
[MAMBUPY]
loggingconf=path/to/logging/config.yamlImportant: When using argparse in programs that import MambuPy, use parse_known_args() instead of parse_args() to avoid conflicts with MambuPy's command-line arguments.
Since v2.0.0, MambuPy uses pyproject.toml for dependency management.
Default Installation (REST API only)
# Using pip
pip install MambuPy
# Using uv (recommended for faster installs)
uv pip install MambuPyIncludes: PyYAML, requests, requests_toolbelt, dateutils, future
Full Installation (REST API + ORM)
# Using pip
pip install MambuPy[full]
# Using uv
uv pip install MambuPy[full]Additional: SQLAlchemy, mysqlclient
Development Installation
# Using pip
pip install MambuPy[dev]
# Using uv (installs dev dependencies in current environment)
uv pip install -e ".[dev]"Includes: freezegun, mock, coverage, pylint, ruff, black, isort
Documentation Build
# Using pip
pip install MambuPy[doc]
# Using uv
uv pip install ".[doc]"Deployment Tools
# Using pip
pip install MambuPy[deploy]
# Using uv
uv pip install ".[deploy]"# Create virtual environment and install with dev dependencies
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
uv pip install -e ".[dev,full]"Recent versions implement a Singleton pattern for HTTP sessions (SessionSingleton in MambuPy/api/connector/rest.py). This allows persistent TCP connections when activate_request_session_objects=True is configured.
REST connector automatically retries failed requests (5 retries by default) for status codes: 429, 500, 502, 503, 504 with exponential backoff.
MambuPy uses Python's logging module. Configure via YAML file specified in loggingconf config option. Logs propagate to parent loggers by default. Important: Logs avoid printing sensitive data (passwords, API keys).
MambuError- Errors from Mambu API responsesMambuCommError- Communication errors with MambuMambuPyError- General MambuPy exceptions
Default pagination limit is 50 items per request (configurable via apipagination). Use OUT_OF_BOUNDS_PAGINATION_LIMIT_VALUE constant for special pagination cases.
- Tests use
unittestframework withmockfor Mambu API responses - Tests are split into:
- Root level: REST v1 and common functionality tests
tests/api/: REST v2 specific teststests/orm/: ORM specific tests
- The
unit.shscript can skip API v2 tests with-a noflag - Coverage reports are generated with each test run
- Line length: 90 characters (black/isort configured)
- Import order: stdlib, third-party, local (enforced by isort)
- Single-line imports enforced then collapsed (isort workflow)
- Ruff checks enabled except E501 (line length, handled by black)
The codebase has a symlink mambupy -> MambuPy for case-insensitive compatibility. The actual source code is in MambuPy/ directory. A CaseInsensitiveFinder meta path finder is also implemented in __init__.py for import flexibility.