Package: one-sdk
Website|Get Started|Documentation|GitHub Discussions|Twitter|SupportSuperface OneSDKOne SDK for all the APIs you want to integrate with.OneClientis a universal API client which provides an unparalleled developer experience for every HTTP API. It enhances resiliency to API changes, and comes with built-in integration monitoring and provider failover.For more details about Superface, visitHow it WorksandGet Started.Important LinksSuperface websiteGet StartedDocumentationSupportInstallTo install OneSDK into the project, run:python3-mpipinstallone-sdkSetupOneClient uses three files (also called Comlink) which together make the integration:Profile- describe business capabilities apart from the implementation details, what is expected as input and what will be the result. Profile name have optional scope before/and required name[scope/]<name>Provider- Define a provider's API services and security schemes to use in a Comlink MapMap- describe implementation details for fulfilling a business capability from a Comlink ProfileTo glue all the parts together, OneClient uses name and file structure convention..
└── superface/ - directory with all the Comlinks in project root
    ├── <profileScope>.<profileName>.profile - profile file
    ├── <providerName>.provider.json - provider file
    ├── <profileScope>.<profileName>.<providerName>.map.js - map file
    └── ... - repeat for all the ComlinksSend email exampleAs an example, lets send an email withMailchimp. The use-case is described in the profilecommunication/send-emailand the map withimplementation.Start with creating a new directorysuperfacein the root of your project.Add the profile. Because profile name contains have scope we need to replace/with.. So, the profile with namecommunication/send-emailhave corresponding filenamecommunication.send-email.profile.Add the provider. The provider name is the same as the filename. So the provider with namemailchimphave corresponding filenamemailchimp.provider.json.Add the map. Map connects profile and provider, so the filename is consists of both as wellcommunication.send-email.mailchimp.map.js.The final structure should look like this:.
└── superface/
    ├── communication.send-email.mailchimp.map.js
    ├── communication.send-email.profile
    └── mailchimp.provider.jsonUseCreate__main__.pyfile with following content and update:importsysfromone_sdkimportOneClient,PerformError,UnexpectedErrorclient=OneClient()profile=client.get_profile("<profileName>")use_case=profile.get_usecase("<usecaseName>")try:r=use_case.perform({# Input parameters as defined in profile:'<key>':'<value>'},provider="<providerName>",# Provider specific integration parameters:parameters={'<integrationParameterName>':'<integrationParameterValue>'},security={# Provider specific security values:'<securityValueId>':{# Security values as described in provider or on profile page}})print(f"RESULT:{r}")exceptPerformErrorase:print(f"ERROR RESULT:{e.error_result}")exceptValidationErrorase:print(f"INVALID INPUT:{e.message}",file=sys.stderr)exceptUnexpectedErrorase:print(f"ERROR:",e,file=sys.stderr)finally:client.send_metrics_to_superface()Then run the script with:python__main__.pyLicenseOneSDK is licensed under theMIT License.© 2023 Superface s.r.o.