Skip to main content

Generic asynchronous i/o python utilities for AWS services (SQS, S3, DynamoDB, Secrets Manager), Redis, MSSQL (pyodbc), JIRA and more

Project description

aioradio

Generic asynchronous i/o python utilities for AWS services (SQS, S3, DynamoDB, Secrets Manager), Redis, MSSQL (pyodbc), JIRA and more.

AWS S3 example code

aioradio abstracts using aiobotocore and aioboto3 making async AWS funtion calls simple one liners. Besides what is shown below in the examples, there is also support for SQS, DynamoDB and Secrets Manager.

import asyncio

from aioradio.aws.s3 import (
    create_bucket,
    delete_s3_object,
    download_file,
    get_object,
    list_s3_objects,
    upload_file
)

async def main():
    s3_bucket = 'aioradio'
    s3_prefix = 'test'
    filename = 'hello_world.txt'
    s3_key = f'{s3_prefix}/{filename}'

    # create an s3 bucket called aioradio
    await create_bucket(bucket=s3_bucket)

    # create hello_world.txt file
    with open(filename, 'w') as file_handle:
        file_handle.write('hello world of aioradio!')

    # upload the file from s3 and confirm it now exists in s3
    await upload_file(bucket=s3_bucket, filepath=filename, s3_key=s3_key)
    assert s3_key in await list_s3_objects(bucket=s3_bucket, s3_prefix=s3_prefix)

    # test downloading the file
    await download_file(bucket=s3_bucket, filepath=filename, s3_key=s3_key)

    # test getting file data to object
    result = await get_object(bucket=s3_bucket, s3_key=s3_key)
    assert result == b'hello world of aioradio!'

    # delete the file from s3
    await delete_s3_object(bucket=s3_bucket, s3_prefix=s3_key)
    assert s3_key not in await list_s3_objects(bucket=s3_bucket, s3_prefix=s3_prefix)

asyncio.get_event_loop().run_until_complete(main())

MSSQL example code

aioredis uses the pyodbc library to work with ODBC databases. It currently has support for connecting and sending queries to mssql.

import asyncio

from aioradio.pyodbc import establish_pyodbc_connection
from aioradio.pyodbc import pyodbc_query_fetchone
from aioradio.pyodbc import pyodbc_query_fetchall

def main():
    conn = establish_pyodbc_connection(host='your-host', user='your-user', pwd='your-password')

    query = "SELECT homeruns FROM MLB.dbo.LosAngelesAngels WHERE lastname = 'Trout' AND year = '2020'"
    row = pyodbc_query_fetchone(conn=conn, query=query)
    print(row)

    query = "SELECT homeruns FROM MLB.dbo.LosAngelesAngels WHERE lastname = 'Trout'"
    rows = pyodbc_query_fetchall(conn=conn, query=query)
    print(rows)


asyncio.get_event_loop().run_until_complete(main())

Jira example code

Jira uses the async library httpx behind the scene to send http requests.

import asyncio

from aioradio.jira import add_comment_to_jira
from aioradio.jira import get_jira_issue
from aioradio.jira import post_jira_issue

async def main():

    # create a jira ticket
    url = 'https://aioradio.atlassian.net/rest/api/2/issue/'
    payload = {
        "fields": {
            "project": {"key": "aioradio"},
            "issuetype": {"name": "Task"},
            "reporter": {"accountId": "somebodies-account-id"},
            "priority": {"name": "Medium"},
            "summary": "Aioradio rocks!",
            "description": "Aioradio Review",
            "labels": ["aioradio"],
            "assignee": {"accountId": "somebodies-account-id"}
        }
    }
    resp = await post_jira_issue(url=url, jira_user='your-user', jira_token='your-password', payload=payload)
    jira_id = resp.json()['key']

    # get jira ticket info
    resp = await get_jira_issue(url=f'{url}/{jira_id}', jira_user='your-user', jira_token='your-password')

    # add comment to jira ticket
    comment = 'aioradio rocks!'
    response = await add_comment_to_jira(url=url, jira_user='your-user', jira_token='your-password', comment=comment)

asyncio.get_event_loop().run_until_complete(main())

INSTALLING FOR DIRECT DEVELOPMENT OF AIORADIO

Install python 3.10.X

Make sure you've installed ODBC drivers, required for using the python package pyodbc.

Clone aioradio locally and navigate to the root directory

Install and activate python VirtualEnv

python3.10 -m venv env
source env/bin/activate

Install python modules included in requirements.txt

pip install -r aioradio/requirements.txt

Run Makefile command from the root directory to test all is good before issuing push to master

make all

AUTHORS

See also the list of contributors who participated in this project.

ACKNOWLEDGEMENTS

  • Pedro Artiga - Developer contributing to aioradio.

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

aioradio-0.17.36.tar.gz (36.7 kB view details)

Uploaded Source

Built Distribution

aioradio-0.17.36-py3-none-any.whl (40.2 kB view details)

Uploaded Python 3

File details

Details for the file aioradio-0.17.36.tar.gz.

File metadata

  • Download URL: aioradio-0.17.36.tar.gz
  • Upload date:
  • Size: 36.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for aioradio-0.17.36.tar.gz
Algorithm Hash digest
SHA256 28a350adb8576eabca5bddee2ba2680eda462b9f64e09968929fc369d199fce8
MD5 1c061af320517a438ae54200cd9a1b2e
BLAKE2b-256 9088a5ee03933fd4b8c26116101ae1c2ccfe57dffc62d7694c1d4add67d2c055

See more details on using hashes here.

Provenance

File details

Details for the file aioradio-0.17.36-py3-none-any.whl.

File metadata

  • Download URL: aioradio-0.17.36-py3-none-any.whl
  • Upload date:
  • Size: 40.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for aioradio-0.17.36-py3-none-any.whl
Algorithm Hash digest
SHA256 61354d75122132a819d3593ec596b29108c5760e7aafbdc9a7e540193bdb2439
MD5 d8d3e5452c10e1619df61c34f7b2b5a4
BLAKE2b-256 605a0899d1e64c2fa47fa23fd75ec4236c3c436a0489a55e2e26fcfd68f9258c

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page