Modular SDK
You use Modular SDK to create, configure, and manage common entities, such as:
- Customers;
- Tenants;
- TenantSettings;
- Regions;
- Applications;
- Parents;
Prerequisites
- Make sure you have the latest version of PyPA’s build installed:
python3 -m pip install --upgrade build
- Run the command form the same directory where
pyptoject.toml
is located: python3 -m build
- This command should output a lot of text and once completed should generate two files in the dist directory:
dist/
modular_sdk-{version}.tar.gz
modular_sdk-{version}-py3-none-any.whl
Installation
Usage
To use Modular SDK, you must import, configure and indicate which service or
services you're going to use:
from modular_sdk.modular import Modular
modular_sdk = Modular()
parent_service = modular_sdk.parent_service()
tenant_service = modular_sdk.tenant_service()
For now, Modular provides 3 ways of DB access. Depends on the way of database
connection, different sets of env variables must be set:
- Onprem, Mongodb:
modular_service_mode
: docker
,
modular_mongo_user
: $MONGO_USER
,
modular_mongo_password
: $MONGO_PASSWORD
,
modular_mongo_url
: $MONGO_URL
,
modular_mongo_db_name
: $MONGO_DB_NAME
, - SaaS, DynamoDB (cross-account access):
modular_service_mode
: saas
# Optional
modular_assume_role_arn
: $ASSUME_ROLE_ARN
- SAAS, DynamoDB (same AWS account):
modular_service_mode
: saas
# Optional
Alternatively, you can pass these parameters (fully or partially) on
initialization:
from modular_sdk.modular import Modular
modular_sdk = Modular(modular_service_mode='docker',
modular_mongo_user='MONGO_USER',
modular_mongo_password='MONGO_PASSWORD',
modular_mongo_url='MONGO_URL',
modular_mongo_db_name='DB_NAME')
application_service = modular_sdk.application_service()
parent_service = modular_sdk.parent_service()
More examples
Example 1: List Maestro Customers
from modular_sdk.modular import Modular
customer_service = Modular().customer_service()
customers = customer_service.list()
for customer in customers:
print(customer.name)
Example 2: Update Maestro Application
from modular_sdk.modular import Modular
application_service = Modular().application_service()
application = application_service.get_application_by_id(
application_id="$APP_ID")
description_to_set = 'Updated application description'
application_service.update(application=application,
description=description_to_set)
application_service.save(application=application)
Example 3: Delete Maestro Parent
from modular_sdk.modular import Modular
parent_service = Modular().parent_service()
parent = parent_service.get_parent_by_id(parent_id="$PARENT_ID")
parent_service.mark_deleted(parent=parent)