Package: aioradio
aioradioGeneric asynchronous i/o python utilities for AWS services (SQS, S3, DynamoDB, Secrets Manager), Redis, MSSQL (pyodbc), JIRA and more.AWS S3 example codeaioradio 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.importasynciofromaioradio.aws.s3import(create_bucket,delete_s3_object,download_file,get_object,list_s3_objects,upload_file)asyncdefmain():s3_bucket='aioradio's3_prefix='test'filename='hello_world.txt's3_key=f'{s3_prefix}/{filename}'# create an s3 bucket called aioradioawaitcreate_bucket(bucket=s3_bucket)# create hello_world.txt filewithopen(filename,'w')asfile_handle:file_handle.write('hello world of aioradio!')# upload the file from s3 and confirm it now exists in s3awaitupload_file(bucket=s3_bucket,filepath=filename,s3_key=s3_key)asserts3_keyinawaitlist_s3_objects(bucket=s3_bucket,s3_prefix=s3_prefix)# test downloading the fileawaitdownload_file(bucket=s3_bucket,filepath=filename,s3_key=s3_key)# test getting file data to objectresult=awaitget_object(bucket=s3_bucket,s3_key=s3_key)assertresult==b'hello world of aioradio!'# delete the file from s3awaitdelete_s3_object(bucket=s3_bucket,s3_prefix=s3_key)asserts3_keynotinawaitlist_s3_objects(bucket=s3_bucket,s3_prefix=s3_prefix)asyncio.get_event_loop().run_until_complete(main())MSSQL example codeaioredis uses the pyodbc library to work with ODBC databases.
It currently has support for connecting and sending queries to mssql.importasynciofromaioradio.pyodbcimportestablish_pyodbc_connectionfromaioradio.pyodbcimportpyodbc_query_fetchonefromaioradio.pyodbcimportpyodbc_query_fetchalldefmain():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 codeJira uses the async library httpx behind the scene to send http requests.importasynciofromaioradio.jiraimportadd_comment_to_jirafromaioradio.jiraimportget_jira_issuefromaioradio.jiraimportpost_jira_issueasyncdefmain():# create a jira ticketurl='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=awaitpost_jira_issue(url=url,jira_user='your-user',jira_token='your-password',payload=payload)jira_id=resp.json()['key']# get jira ticket inforesp=awaitget_jira_issue(url=f'{url}/{jira_id}',jira_user='your-user',jira_token='your-password')# add comment to jira ticketcomment='aioradio rocks!'response=awaitadd_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 AIORADIOInstallpython 3.11.XMake sure you've installedODBC drivers, required for using the python package pyodbc.Clone aioradio locally and navigate to the root directoryInstall and activate python VirtualEnvpython3.11-mvenvenvsourceenv/bin/activateInstall python modules included in requirements.txtpipinstallcython
pipinstall-raioradio/requirements.txtRun Makefile command from the root directory to test all is good before issuing push to mastermake allAUTHORSTim Reichard-aioradioSee also the list ofcontributorswho participated in this project.ACKNOWLEDGEMENTSPedro Artiga- Developer contributing to aioradio.