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.0.tar.gz (112.0 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.0-py3-none-any.whl (2.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pairasync-1.0.0.tar.gz
Algorithm Hash digest
SHA256 bbc896283ed2d4a4dbd351bcfffe366513df0d8a1cab6476eced9a7d73141dcb
MD5 c3925e83f9b9c5dab61fadbe8ad76523
BLAKE2b-256 f3ba96fd8ffaac8591867b8bf6b4a38fc3a1f12dcce7367b97e19f632a06fa10

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pairasync-1.0.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-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 72219daceb6348a00be70210cb131a500a3b3199ce9b8147aa55c4a74f87c38b
MD5 fda342bfce370c63b7d4b82fe0c27430
BLAKE2b-256 a17a4acd4e9599e646d8e78e54c6c323b83391da8d0cf3fc35d5a9b5a71a0b27

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