Skip to main content

SDK for facilitating the communication with Maestro for all Pythonic components

Project description

Maestro-python-sdk

The 'Maestro Python SDK' is an SDK created for facilitating the communication with Maestro for all Pythonic components including: WSBA, SFTA, Consumption Module, Automover BA etc.

Contents

Requirements

Python 3.10 required

Installation

First of all you need to install m3-python-sdk to your project, you can use next command to do it:

  • pip install maestro-python-sdk

After you installed maestro-python-sdk to your project, you should set ENV variables, this step is optional, because you would be able to pass those params while creating instances, but we highly recommend you to do this, because it will make your use more pleasant and flexible, and also such a method is more secure.

  • SDK_ACCESS_KEY,
  • SDK_SECRET_KEY,
  • MAESTRO_USER,

This is first required variables you should set, the following variables depend on the way you will be using the SDK.

Rabbit

  • RABBIT_EXCHANGE,
  • DEFAULT_MAESTRO_REQUEST_QUEUE, DEFAULT_MAESTRO_RESPONSE_QUEUE,
  • DEFAULT_ADMIN_REQUEST_QUEUE, DEFAULT_ADMIN_RESPONSE_QUEUE,
  • DEFAULT_KPI_REQUEST_QUEUE, DEFAULT_KPI_RESPONSE_QUEUE

HTTP

  • API_LINK

USAGE

To start using Maestro Python SDK you need to create either an HTTP client or a RabbitMQ client. The difference between them is not significant. If you need to send asynchronous requests, use only the RabbitMQ client, as it is the only one that supports such functionality. In other cases, use whichever is more convenient for you.

RabbiMQ

There are two ways to create RabbitMQ client:

  • Create client using __init__ method of a RabbitMqStrategy class:
  • Create client using build method of a RabbitMqStrategy class:

__init__ method Example

Step 1: Create a RabbitMqStrategy object. This step requires the following information: rabbit connection url for maestro server, your personal sdk access and secret keys, maestro user and names of rabbit queues, more information about parameters is described inside RabbitMqStrategy class. Below is an example of how to create a client:

  1. from m3_python_sdk.strategies.rabbitmq import RabbitMqStrategy
    rabbit_client = RabbitMqStrategy(
         connection_url='<connection url>',
         request_queue='<request_queue>',
         response_queue='<response_queue>',
         sdk_access_key='<sdk_access_key>',
         sdk_secret_key='<sdk_secret_key>',
         maestro_user='<maestro_user>'
    )
    # For your information, request/response queues, sdk keys and maestro user
    # could be set as ENV varibles, if you dont provide them while creating class,
    # they would be searched in env variables automatically.
    

Step 2: If you provided sdk with correct credentials and parameters you are good to go to use SDK. An examples is provided in the "Examples" topic.

BUILD method Example

Step 1: Create a RabbitMqStrategy object. This step requires the following information: host, username and password, stage, amqps and everything that takes basic init method. Below is an example of how to create a client:

  1. rabbit_client = RabbitMqStrategy(
         host='<host123.eu.amazon>',
         stage='<mstrdev>',
         username='<username>',
         password='<password>',
         request_queue='<request_queue>',
         response_queue='<response_queue>',
         sdk_access_key='<sdk_access_key>',
         sdk_secret_key='<sdk_secret_key>',
         maestro_user='<maestro_user>'
    )
    
    #as result you will get next rabbit_url:  
     'amqps://username:password@host123.eu.amazon:5671/mstrdev'
    
    # For your information, request/response queues, sdk keys and maestro user'
    # could be set as ENV varibles, if you dont provide them while creating class,
    # they would be searched in env variables automatically.
    

Step 2: If you provided sdk with correct credentials and parameters you are good to go to use SDK. An examples is provided in the "Examples" topic. Now that you have created the client, you can use it to interact with the SDK. An example is provided in the "Examples" topic.

HTTP

There are two ways to create HTTP client:

  • Create client using __init__ method of a HTTPStrategy class:
  • Create client using build method of a HTTPStrategy class:

__init__ method Example

Step 1: Create a HTTPStrategy object. This step requires the following information: api_link for maestro server, your personal sdk access and secret keys and maestro user, more information about parameters is described inside HTTPStrategy class. Below is an example of how to create a client:

  1. from m3_python_sdk.strategies.http import HTTPStrategy
    http_client = HTTPStrategy(
         api_link='<api link>',
         sdk_access_key='<sdk_access_key>',
         sdk_secret_key='<sdk_secret_key>',
         maestro_user='<maestro_user>'
    )
    # For your information, sdk keys and maestro user could be set as ENV varibles,
    # if you dont provide them while creating class,
    # they would be searched in env variables automatically.
    # Namings for ENV variables:
    

Step 2: If you provided sdk with correct credentials and parameters you are good to go to use SDK. An examples is provided in the "Examples" topic.

BUILD method Example

Step 1: Create a HTTPStrategy object. This step requires the following information: host, port, stage, htpps, and everything that takes basic init method except api_link. Below is an example of how to create a client:

  1. http_client = HTTPStrategy(
         host='<m3.cloud.com>',
         stage='<maestro/api/v3>',
         port='8000',
         https='True',
         sdk_access_key='<sdk_access_key>',
         sdk_secret_key='<sdk_secret_key>',
         maestro_user='<maestro_user>'
    )
    
    #as result you will get next api_link:  
     https://m3.cloud.com:8000/maestro/api/v3
    
    # For your information, request/response queues, sdk keys and maestro user'
    # could be set as ENV varibles, if you dont provide them while creating class,
    # they would be searched in env variables automatically.
    # SDK_ACCESS_KEY, SDK_SECRET_KEY, MAESTRO_USER, API_LINK
    

Step 2: If you provided sdk with correct credentials and parameters you are good to go to use SDK. An examples is provided in the "Examples" topic. Now that you have created the client, you can use it to interact with the SDK. An example is provided in the "Examples" topic.

EXAMPLES

When you create a basic HTTP ot RabbitMQ clients using one of provided ways, you can use it to call some methods.

In general, methods are separated into next categories:

  • Consumptions
    • add_consumption
    • get_consumption
    • delete_consumption
    • add_consumption_details
    • get_consumption_details
    • delete_consumption_details
    • check_tenant_status
  • Adjustments
    • add_adjustment
    • get_adjustment
    • delete_adjustment
    • total_report
  • Billing
    • describe_billing_month
    • describe_currency
    • get_top_account_reports
    • add_cost_center
    • archive_big_query
    • billing_configure

Here are examples of how to call one method from each category.

  1. # You need to create Http ot Rabbit client, after that create ConsumptionResource class object and pass your client inside init method
    from m3_python_sdk.strategies.http import HttpStrategy
    from m3_python_sdk.resources.consumption.consumption import ConsumptionResource
    http = HttpStrategy(#the example is given above.)
    consumption = ConsumptionResource(client=http)
    consumption.get_consumption(
           source_project='example',
           target_project='example',
           target_region='example',
           year=example,
           month=example,
           description='example'
    )
    
    response: {'status_code': status_code, 'status': status, 'message': message}
    # Remember that response could also have next params: data, items, table_title, warnings, code
    
  1. # You need to create Http ot Rabbit client, after that create AdjustmentResource class object and pass your client inside init method
    from m3_python_sdk.strategies.rabbitmq import RabbitMqStrategy
    from m3_python_sdk.resources.consumption.adjustment import AdjustmentResource
    rabbit = RabbitMqStrategy(#the example is given above.)
    adjustment = AdjustmentResource(client=rabbit)
    adjustment.get_adjustment(
           target_project='example',
           target_account_number='example',
           target_region='example',
           #target_cloud='example',
           month='example',
           year='example',
           description='example',
           credit_type='example',
           currency_native='example',
           value='example'
    )
    
    response: {'status_code': status_code, 'status': status, 'message': message}
    # Remember that response could also have next params: data, items, table_title, warnings, code
    
  1. # You need to create Http ot Rabbit client, after that create BillingResource class object and pass your client inside init method
    ## Also if you already have some strategy created and you used it for consumptions or adjustment, you need to change Queues using properties.
    from m3_python_sdk.strategies.rabbitmq import RabbitMqStrategy
    from m3_python_sdk.resources.billing.billing import BillingResource
    rabbit = RabbitMqStrategy(#the example is given above.)
    billing = BillingResource(client=rabbit)
    billing.describe_billing_month(year=2023, month=11)
    
    response: {'status_code': status_code, 'status': status, 'message': message}
    # Remember that response could also have next params: data, items, table_title, warnings, code
    
Remember, the full list of endpoints can be found inside the consumption.py, adjustment.py and billing.py files. Additionally, greater amount of the endpoints can accept additional arguments, which can also be found inside those files.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

maestro_python_sdk-1.1.0.tar.gz (35.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

maestro_python_sdk-1.1.0-py3-none-any.whl (32.3 kB view details)

Uploaded Python 3

File details

Details for the file maestro_python_sdk-1.1.0.tar.gz.

File metadata

  • Download URL: maestro_python_sdk-1.1.0.tar.gz
  • Upload date:
  • Size: 35.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for maestro_python_sdk-1.1.0.tar.gz
Algorithm Hash digest
SHA256 766f8b2975f86f2d17a9188dfcee3e45df7d35c5b35f639d339d6cb9feb2226b
MD5 bc1c71eb7f1b6659029d057e9d3b9144
BLAKE2b-256 935e4700d220d31d222e7dbe787a203b486d3b3792ce999a4020ec48cab7c5a7

See more details on using hashes here.

File details

Details for the file maestro_python_sdk-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for maestro_python_sdk-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7ee98894a2a506aac6c781ca3b4f8d3b6ed8bb69fea7de20956f8d1c36c55b07
MD5 d1a6b69ba30ef19eba315e3c8148f3d1
BLAKE2b-256 f4d1e98cd7db98c04d591ca62646c5d81130acd22316c0c26cc18de8dc23949c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page