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-1.0.1.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

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

pairasync-1.0.1-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pairasync-1.0.1.tar.gz
Algorithm Hash digest
SHA256 2cb9ee77cc2605613da7bf623333251e3b6bf387f18769182c6e1c8258fcce19
MD5 f8d7cc1ba3d7ef58512fbbaa563e83aa
BLAKE2b-256 72276cf987c4e953ad40fa8b31e0a3646b1034f356c49e8095bf971dda7a40bb

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pairasync-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7271cd69728910dedda0c2bb03b0e1192b66c06d12575c6ac84bd0c7d97f41b7
MD5 68e1092baee6766727e746fa8318cb4a
BLAKE2b-256 36d4e2fa155e74dfcc16ec0ad3dc1c35f7b2974bb9f16e071882b96e03408925

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