Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

async-to-sync

Package Overview
Dependencies
Maintainers
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-to-sync

Convert async coroutines to normal python functions

  • 0.2.3
  • PyPI
  • Socket score

Maintainers
2

============= async_to_sync

Convert async coroutine functions to normal ones.

Installation

.. code-block:: bash

$ pip install async_to_sync

Usage

.. code-block:: python

import async_to_sync as sync

# an async object method to demonstrate use
class async_class:
    async def sum(self, a, b):
        return a + b
async_object = async_class()

# wrap all async methods of an object
sync_object = sync.methods(async_object)

assert sync_object.sum(1,2) == 3

# wrap a single async callable
sync_function = sync.function(async_object.sum)

assert sync_function(4,5) == 9

# wait for a coroutine
sync_result = sync.coroutine(async_object.sum(6,7))

assert sync_result == 13

# manually stop default event loop
sync.stop()

# manually start default event loop
sync.start()

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc