# wayscript-python
## Context
```
from wayscript import context
event = context.get_event()
```
### Checking user by application key
```
from wayscript import context, utils
application_key = utils.get_application_key()
user = context.get_user_by_application_key(application_key)
```
## Triggers
### HTTP Triggers
```
from wayscript.triggers import http_trigger
payload = {"hello": "world"}
headers = {"content-type": "application/json"}
status_code = 200
http_trigger.send_response(data=payload, headers=headers, status_code=status_code)
```
## Integrations
### SQL
To connect to a postgres resource, use the following snippet:
```
import psycopg2
from wayscript.integrations import sql
kwargs = sql.get_psycopg2_connection_kwargs(_id)
connection = psycopg2.connect(**kwargs)
```
## Secrets
### Create/Update Secret
To create a new secret, or update an existing one:
```
from wayscript import secret_manager
my_secret_value = "an application key or other private information"
secret_manager.set_secret('my_secret_key', my_secret_value)
```
To test an existing secret, and update if the secret is no longer valid (expired authorization token):
```
import os
from wayscript import secret_manager
# Retrieve existing key from secret
auth_key = os.getenv('AUTH_KEY_MAY_EXPIRE')
# Test connection to service using auth_key
if not authorized:
# Get new auth_key from service
auth_key = 'New Key From Service Request'
secret_manager.set_secret('AUTH_KEY_MAY_EXPIRE', auth_key)
# Continue flow as normal
```
Raw data
{
"_id": null,
"home_page": "https://github.com/wayscript/wayscript-python",
"name": "wayscript",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "wayscript,productivity,software,scripts,cloud,tools,backend,trigger,integration,dev,http,webhook",
"author": "Team WayScript",
"author_email": "founders@wayscript.com",
"download_url": "https://files.pythonhosted.org/packages/89/e6/a5f45a9433aaf346e0eb13098ed0a84d528ddaecb24c5f9e98abb188b367/wayscript-0.4.0.tar.gz",
"platform": null,
"description": "# wayscript-python\n\n## Context\n\n```\nfrom wayscript import context\n\nevent = context.get_event()\n```\n\n### Checking user by application key\n```\nfrom wayscript import context, utils\n\napplication_key = utils.get_application_key()\nuser = context.get_user_by_application_key(application_key)\n```\n## Triggers\n\n### HTTP Triggers\n\n```\nfrom wayscript.triggers import http_trigger\n\npayload = {\"hello\": \"world\"}\nheaders = {\"content-type\": \"application/json\"}\nstatus_code = 200\n\nhttp_trigger.send_response(data=payload, headers=headers, status_code=status_code)\n```\n\n## Integrations\n\n### SQL\n\nTo connect to a postgres resource, use the following snippet:\n```\nimport psycopg2\nfrom wayscript.integrations import sql\n\nkwargs = sql.get_psycopg2_connection_kwargs(_id)\nconnection = psycopg2.connect(**kwargs)\n```\n\n## Secrets\n\n### Create/Update Secret\n\nTo create a new secret, or update an existing one:\n```\nfrom wayscript import secret_manager\n\nmy_secret_value = \"an application key or other private information\"\nsecret_manager.set_secret('my_secret_key', my_secret_value)\n \n```\n\nTo test an existing secret, and update if the secret is no longer valid (expired authorization token):\n```\nimport os\nfrom wayscript import secret_manager\n\n# Retrieve existing key from secret\nauth_key = os.getenv('AUTH_KEY_MAY_EXPIRE')\n\n# Test connection to service using auth_key\nif not authorized:\n # Get new auth_key from service\n auth_key = 'New Key From Service Request'\n secret_manager.set_secret('AUTH_KEY_MAY_EXPIRE', auth_key)\n\n# Continue flow as normal\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Quickly build services, data pipelines, internal tools, and more.",
"version": "0.4.0",
"split_keywords": [
"wayscript",
"productivity",
"software",
"scripts",
"cloud",
"tools",
"backend",
"trigger",
"integration",
"dev",
"http",
"webhook"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "89e6a5f45a9433aaf346e0eb13098ed0a84d528ddaecb24c5f9e98abb188b367",
"md5": "d2a4346c819971a4ce22607d7300504a",
"sha256": "70dcd34c95d8dd7c4519524c24a552215d05f0bb711a8c47fd92cc281086551a"
},
"downloads": -1,
"filename": "wayscript-0.4.0.tar.gz",
"has_sig": false,
"md5_digest": "d2a4346c819971a4ce22607d7300504a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 7911,
"upload_time": "2023-02-02T21:43:25",
"upload_time_iso_8601": "2023-02-02T21:43:25.698457Z",
"url": "https://files.pythonhosted.org/packages/89/e6/a5f45a9433aaf346e0eb13098ed0a84d528ddaecb24c5f9e98abb188b367/wayscript-0.4.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-02-02 21:43:25",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "wayscript",
"github_project": "wayscript-python",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"circle": true,
"lcname": "wayscript"
}