Skip to main content

Pair async code to your sync code

Project description

PairAsync | Seamless Async-Sync Integration for Python

PyPI version License: MIT Python 3.7+

PairAsync is a Python library that combines asynchronous (async) with synchronous (sync) code, enabling developers to execute async functions within sync environments. Ideal for enhancing Python applications from version 3.7 onwards, PairAsync simplifies the integration of asynchronous operations into traditional synchronous codebases.

Installation

Get started with PairAsync by installing it via pip:

pip install pairasync

Key Features

  • Run Async Functions Sync: Execute simple async functions synchronously and retrieve results instantly.
  • Custom Async Handling: For more complex async tasks, create tailored async functions and pair them with your sync code without converting your entire codebase to async.

Usage

Simple Async Function Execution

use PairAsync to run basic async functions in a sync context:

from pairasync import sync
import asyncio

async def simple_async_func():
    await asyncio.sleep(1)
    return "Hello from async!"

result = sync(simple_async_func())
print(result)  # Output: Hello from async!

Complex Async Scenarios

For complex scenarios running side effect prone functions or when using a larger event driven library (selenium, aiohttp, asyncpg) define your async function then run it in a sync context:

from pairasync import sync
import aiohttp

async def get_text(url):
    async with aiohttp.ClientSession() as session:
        async with session.get(url) as response:
            return await response.text()

class SomeClass:

    def __init__(self):
        result = sync(get_text("https://example.com"))
        print(result)

object = SomeClass() 

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pairasync-0.1.0.tar.gz (112.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pairasync-0.1.0-py3-none-any.whl (2.6 kB view details)

Uploaded Python 3

File details

Details for the file pairasync-0.1.0.tar.gz.

File metadata

  • Download URL: pairasync-0.1.0.tar.gz
  • Upload date:
  • Size: 112.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.11

File hashes

Hashes for pairasync-0.1.0.tar.gz
Algorithm Hash digest
SHA256 59e3e2e3ded605c1022c852d77d852b554528a918907474b0fcd6250f240fe7c
MD5 647630aeeb10a247f9d78428bd0f34fa
BLAKE2b-256 4a227c19b1e93ad9c2bd8bbebf768f841fe6d973134cf2ad5c57d1c8cae8f3f7

See more details on using hashes here.

File details

Details for the file pairasync-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pairasync-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 2.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.11

File hashes

Hashes for pairasync-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 798d5a221850f71a5c240e25cf3f9c2b551c0e6036c9111d2970aa610c7aaa1e
MD5 0294f06f5cc0942603ace22c4173b888
BLAKE2b-256 6e37a9b0f5a2ff5ba6ad564a973a0faa25b07d77c35f1276d24cbd689e372312

See more details on using hashes here.

Supported by

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