Skip to main content

Connect Python SDK

Project description

Connect Python SDK

pyversions PyPi Status codecov Build Status PyPI status

Getting Started


Connect Python SDK allows an easy and fast integration with Connect fulfillment API. Thanks to it you can automate the fulfillment of orders generated by your products.

In order to use this library, please ensure that you have read first the documentation available on Connect knowledge base article located here, this one will provide you a great information on the rest api that this library implements.

Class Features


This library may be consumed in your project in order to automate the fulfillment of requests, this class once imported into your project will allow you to:

  • Connect to Connect using your api credentials
  • List all requests, and even filter them:
    • for a Concrete product
    • for a concrete status
  • Process each request and obtain full details of the request
  • Modify for each request the activation parameters in order to:
    • Inquiry for changes
    • Store information into the fulfillment request
  • Change the status of the requests from it's initial pending state to either inquiring, failed or approved.
  • Generate logs
  • Collect debug logs in case of failure

Your code may use any scheduler to execute, from a simple cron to a cloud scheduler like the ones available in Azure, Google, Amazon or other cloud platforms.

Installation

$ pip install connect-sdk

Requirements

Example

from connect import FulfillmentAutomation, TierConfigAutomation
from connect.logger import logger
from connect.models import ActivationTemplateResponse, ActivationTileResponse
from connect.models.exception import FulfillmentFail, FulfillmentInquire, Skip


class ExampleRequestProcessor(FulfillmentAutomation):
    def process_request(self, request):
    
        logger.info('Processing request {} for contract {}, product {}, marketplace {}'
                    .format(request.id,
                            request.contract.id,
                            request.asset.product.name,
                            request.marketplace.name))

        # Custom logic
        if request.type == 'purchase':
            for item in request.asset.items:
                if item.quantity > 100000:
                    raise FulfillmentFail(
                        message='Is Not possible to purchase product')

            for param in request.asset.params:
                if param.name == 'email' and not param.value:
                    param.value_error = 'Email address has not been provided, please provide one'
                    raise FulfillmentInquire(params=[param])

            # Approve by ActivationTile
            return ActivationTileResponse('\n  # Welcome to Fallball!\n\nYes, '
                                          'you decided to have an account in our amazing service!')
            # Or
            # return TemplateResource().render(pk='TEMPLATE_ID', request_id=request.id)

            # Approve by Template
            return ActivationTemplateResponse('TL-497-535-242')
            # Or
            # return TemplateResource().get(pk='TEMPLATE_ID')

        elif request.type == 'change':
            # Fail
            raise FulfillmentFail()
        else:
            # Skip request
            raise Skip()


class ExampleTierConfigProcessor(TierConfigAutomation):
    def process_request(self, request):
        pass


if __name__ == '__main__':
    request_processor = ExampleRequestProcessor()
    request_processor.process()

    tier_config_processor = ExampleTierConfigProcessor()
    tier_config_processor.process()

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

connect-sdk-15.2.tar.gz (15.7 kB view details)

Uploaded Source

File details

Details for the file connect-sdk-15.2.tar.gz.

File metadata

  • Download URL: connect-sdk-15.2.tar.gz
  • Upload date:
  • Size: 15.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/2.7.14

File hashes

Hashes for connect-sdk-15.2.tar.gz
Algorithm Hash digest
SHA256 162d9e9a68c56aee95e4f82f7f0009fcd7d1e9794540a587e87e53f7d00151c6
MD5 b75cded55270a5a3cad71c25f2f222e3
BLAKE2b-256 733cba181b22850da4fca0f04c3d76bab631f6572417e71609fa25185aed039c

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