Async to sync converter
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
docs Bump version: 1.2.2 → 1.3.0 Jun 3, 2017
tests Update Aug 15, 2017
.coveragerc Use tox on travis Feb 15, 2018
.travis.yml Run tests on python3.7 Jul 3, 2018
LICENSE First commit Feb 23, 2016
README.rst Update info Mar 24, 2016
requirements-docs.txt Use tox on travis Feb 15, 2018
requirements-test.txt Use tox on travis Feb 15, 2018
tox.ini Run tests on python3.7 Jul 3, 2018



Syncer is an async-to-sync converter for python.


Sometimes (mainly in test) we need to convert asynchronous functions to normal, synchronous functions and run them synchronously. It can be done by ayncio.get_event_loop().run_until_complete(), but it's quite long...

Syncer makes this conversion easy.

  • Convert coroutine-function (defined by aync def) to normal (synchronous) function
  • Run coroutines synchronously
  • Support both async def and decorator (@asyncio.coroutine) style


At the command line:

$ pip install syncer


This module has only one function: syncer.sync.

from syncer import sync
async def async_fun():
    return 1
b = sync(async_fun)  # now b is synchronous
assert 1 == b()

To test the above async_fun in asynchronous test functions:

import unittest

class TestA(unittest.TestCase):
    # ``sync`` can be used as decorator.
    # The decorated function becomes synchronous.
    async def test_async_fun(self):
        self.assertEqual(await async_fun(), 1)

Or, keep test functions synchronous and get results synchronously:

class TestA(unittest.TestCase):
    def test_async_fun(self):
        # run coroutine and return the result
        self.assertEqual(sync(async_fun()), 1)
        # This is equivalent to below, just a shortcut
            asyncio.get_event_loop().run_until_complete(async_fun()), 1)

More examples/use-cases will be found in test.


MIT license


This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.