OneSDK is a universal API client which provides an unparalleled developer experience for every HTTP API
Project description
Website | Get Started | Documentation | GitHub Discussions | Twitter | Support
Superface OneSDK
One SDK for all the APIs you want to integrate with.
OneClient
is 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, visit How it Works and Get Started.
Important Links
Install
To install OneSDK into the project, run:
python3 -m pip install one-sdk
Setup
OneClient 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 Map
- Map - describe implementation details for fulfilling a business capability from a Comlink Profile
To 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 Comlinks
Send email example
As an example, lets send an email with Mailchimp. The use-case is described in the profile communication/send-email and the map with implementation.
- Start with creating a new directory
superface
in 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-email
have corresponding filenamecommunication.send-email.profile
. - Add the provider. The provider name is the same as the filename. So the provider with name
mailchimp
have corresponding filenamemailchimp.provider.json
. - Add the map. Map connects profile and provider, so the filename is consists of both as well
communication.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.json
Use
Create __main__.py
file with following content and update:
import sys
from one_sdk import OneClient, PerformError, UnexpectedError
client = 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}")
except PerformError as e:
print(f"ERROR RESULT: {e.error_result}")
except ValidationError as e:
print(f"INVALID INPUT: {e.message}", file = sys.stderr)
except UnexpectedError as e:
print(f"ERROR:", e, file = sys.stderr)
finally:
client.send_metrics_to_superface()
Then run the script with:
python __main__.py
License
OneSDK is licensed under the MIT License.
© 2023 Superface s.r.o.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file one_sdk-1.0.0b12.tar.gz
.
File metadata
- Download URL: one_sdk-1.0.0b12.tar.gz
- Upload date:
- Size: 1.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dea9342f66aee7f17ebc4bc32a73f924a4910661b8e1b4c9ce96ac2aaacf4bb5 |
|
MD5 | 6431dc49ab9d3ce309ae5a8635afe626 |
|
BLAKE2b-256 | 57d34a4b48dbaa84e45dbb196c399697c8b4fdfc220e9d588673b8325c82cd43 |
File details
Details for the file one_sdk-1.0.0b12-py3-none-any.whl
.
File metadata
- Download URL: one_sdk-1.0.0b12-py3-none-any.whl
- Upload date:
- Size: 1.2 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5aeb9b698dbbbe64b42d5adddb718738a592e479361b21d48fdaabfe94866a42 |
|
MD5 | 1f49d4388336a794c5fee4ca129ed171 |
|
BLAKE2b-256 | 93b99c5e521dd99217c35eef2a5ec2037afe9b4b9ad813299bd06f8a629fbd9b |