# swimlane-connector-utilities
This package contains utility functions to be used in Swimlane Connectors.
## Swimlane Attachments
This helper function is to create attachments easily, in Swimlane output format. You can either create a single attachment, with create_attachment
```python
from swimlane_connector_utilities import create_attachment
output = {
"attachment_key1": create_attachment("myfile.txt", "this is a text file")
"attachment_key2": create_attachment("myfile.exe", <byte data here>)
}
```
Or multiple attachments with SwimlaneAttachments
```python
from swimlane_connector_utilities import SwimlaneAttachments
swa = SwimlaneAttachments()
swa.add_attachment("myfile.txt", "this is a text file")
swa.add_attachment("myfile.exe", <byte data here>)
output = {
"attachment_list": swa.get_attachments()
}
```
## Create Test Connection
Creating test connections can be repetitive, so a test connection that looks like this:
```python
from swimlane_connector_utilities import create_test_conn
# My Integration Auth, copied from __init__.py for example purposes
class MyIntegration(object):
def __init__(self, context):
# Do auth here
pass
def do_auth(self):
pass
class SwMain(object):
def __init__(self, context):
self.context = context
def execute(self):
try:
MyIntegration(self.context).do_auth()
return {"successful": True}
except Exception as e:
return {"successful": False, "errorMessage": str(e)}
```
Can be easily turned into
```python
from swimlane_connector_utilities import create_test_conn
# My Integration Auth, copied from __init__.py for example purposes
class MyIntegration(object):
def __init__(self, context):
# Do auth here
pass
def do_auth(self):
pass
SwMain = create_test_conn(MyIntegration, execute_func="do_auth")
```
Note that if you do authentication in __init__ you can exclude the execute_func param
## Parse Datetime
datetime inputs can be many different formats and often we want to accept a time relative
to the current time, such as `10 minutes ago`. To handle all datetime inputs, you can use
the function `parse_datetime`. This function accepts all common datetime formats as well
as the relative time format below, and returns a pendulum object. An `InvalidInput` error
will be raised if it is not a valid datetime.
### Relative datetime format:
```
For the current time:
now
Any other time:
(+/-)(integer) (milliseconds|seconds|minutes|days|weeks|months|years)
examples:
now
-1 months
+3 days
-123 seconds
```
parse_datetime can be used to parse the input, then convert the pendulum object to the format the
api requires.
```python
from swimlane_connector_utilities import parse_datetime
data = {"time_1": "2020-02-02 10:10:10", "time_2": "-5 minutes", "text_field": "text"}
for field in ["time_1", "time_2"]:
data[field] = parse_datetime(field, data[field]).to_iso8601_string()
```
Raw data
{
"_id": null,
"home_page": "https://github.com/swimlane/swimlane-connector-utilities",
"name": "swimlane-connector-utilities",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": null,
"author": "Swimlane",
"author_email": "info@swimlane.com",
"download_url": "https://files.pythonhosted.org/packages/74/7f/db2fd8ac782e5a1eb8e7447ef330495487919dea3aed53e6f232aa710b71/swimlane_connector_utilities-1.1.0.tar.gz",
"platform": null,
"description": "# swimlane-connector-utilities\n\nThis package contains utility functions to be used in Swimlane Connectors.\n\n## Swimlane Attachments\nThis helper function is to create attachments easily, in Swimlane output format. You can either create a single attachment, with create_attachment\n```python\nfrom swimlane_connector_utilities import create_attachment\n\noutput = {\n \"attachment_key1\": create_attachment(\"myfile.txt\", \"this is a text file\")\n \"attachment_key2\": create_attachment(\"myfile.exe\", <byte data here>)\n}\n```\nOr multiple attachments with SwimlaneAttachments\n```python\nfrom swimlane_connector_utilities import SwimlaneAttachments\n\n\nswa = SwimlaneAttachments()\n\n\nswa.add_attachment(\"myfile.txt\", \"this is a text file\")\nswa.add_attachment(\"myfile.exe\", <byte data here>)\n\n\noutput = {\n \"attachment_list\": swa.get_attachments()\n}\n```\n\n## Create Test Connection\nCreating test connections can be repetitive, so a test connection that looks like this:\n```python\nfrom swimlane_connector_utilities import create_test_conn\n\n# My Integration Auth, copied from __init__.py for example purposes\nclass MyIntegration(object):\n def __init__(self, context):\n # Do auth here\n pass\n\n def do_auth(self):\n pass\n\n\nclass SwMain(object):\n def __init__(self, context):\n self.context = context\n\n def execute(self):\n try:\n MyIntegration(self.context).do_auth()\n\n return {\"successful\": True}\n except Exception as e:\n return {\"successful\": False, \"errorMessage\": str(e)}\n```\nCan be easily turned into\n```python\nfrom swimlane_connector_utilities import create_test_conn\n\n# My Integration Auth, copied from __init__.py for example purposes\nclass MyIntegration(object):\n def __init__(self, context):\n # Do auth here\n pass\n\n def do_auth(self):\n pass\n \nSwMain = create_test_conn(MyIntegration, execute_func=\"do_auth\")\n```\nNote that if you do authentication in __init__ you can exclude the execute_func param\n\n## Parse Datetime\n\ndatetime inputs can be many different formats and often we want to accept a time relative \nto the current time, such as `10 minutes ago`. To handle all datetime inputs, you can use\nthe function `parse_datetime`. This function accepts all common datetime formats as well \nas the relative time format below, and returns a pendulum object. An `InvalidInput` error\nwill be raised if it is not a valid datetime.\n\n### Relative datetime format:\n```\nFor the current time:\n now\nAny other time:\n (+/-)(integer) (milliseconds|seconds|minutes|days|weeks|months|years)\n \nexamples:\n now\n -1 months\n +3 days\n -123 seconds\n```\n\nparse_datetime can be used to parse the input, then convert the pendulum object to the format the\napi requires.\n```python\nfrom swimlane_connector_utilities import parse_datetime\n\ndata = {\"time_1\": \"2020-02-02 10:10:10\", \"time_2\": \"-5 minutes\", \"text_field\": \"text\"}\nfor field in [\"time_1\", \"time_2\"]:\n data[field] = parse_datetime(field, data[field]).to_iso8601_string()\n```\n",
"bugtrack_url": null,
"license": null,
"summary": "Functions to simplify Swimlane connector development.",
"version": "1.1.0",
"project_urls": {
"Bug Tracker": "https://github.com/swimlane/swimlane-connector-utilities/issues",
"Homepage": "https://github.com/swimlane/swimlane-connector-utilities"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "1a28a21854ec8e92b9168374886e7275960d54566bd2eef057941550eaecb00c",
"md5": "09c947b81494146ed27bf911b5cc884f",
"sha256": "eada9736dc722411a512bf4dfcb02b15b6df090499a8108f639b3a276f52dc40"
},
"downloads": -1,
"filename": "swimlane_connector_utilities-1.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "09c947b81494146ed27bf911b5cc884f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 7284,
"upload_time": "2024-07-03T16:54:31",
"upload_time_iso_8601": "2024-07-03T16:54:31.843640Z",
"url": "https://files.pythonhosted.org/packages/1a/28/a21854ec8e92b9168374886e7275960d54566bd2eef057941550eaecb00c/swimlane_connector_utilities-1.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "747fdb2fd8ac782e5a1eb8e7447ef330495487919dea3aed53e6f232aa710b71",
"md5": "451f815e0a568c6dfdc5ebb8b8894695",
"sha256": "acf59b31937bb64c81d0186b3bbc046bb05d396ca45876214a490a4224c4f6a3"
},
"downloads": -1,
"filename": "swimlane_connector_utilities-1.1.0.tar.gz",
"has_sig": false,
"md5_digest": "451f815e0a568c6dfdc5ebb8b8894695",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 11625,
"upload_time": "2024-07-03T16:54:33",
"upload_time_iso_8601": "2024-07-03T16:54:33.489774Z",
"url": "https://files.pythonhosted.org/packages/74/7f/db2fd8ac782e5a1eb8e7447ef330495487919dea3aed53e6f232aa710b71/swimlane_connector_utilities-1.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-03 16:54:33",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "swimlane",
"github_project": "swimlane-connector-utilities",
"github_not_found": true,
"lcname": "swimlane-connector-utilities"
}