Syncer
Syncer is an async-to-sync converter for python.
Documentation: https://miyakogi.github.io/syncer/
Source code: https://github.com/miyakogi/syncer/
Features
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 async-function (defined by aync def) to normal (synchronous) function
Evaluate coroutines synchronously
Install
At the command line:
$ pip install syncer
Usage
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.
@sync
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
self.assertEqual(
asyncio.get_event_loop().run_until_complete(async_fun()), 1)
More examples/use-cases will be found in test.
License
Credits
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.
Metadata
Release files for syncer 2.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| syncer-2.0.3.tar.gz | 11.5 kB | Without provenance | Details for syncer-2.0.3.tar.gz |
Release files / syncer-2.0.3.tar.gz
| Download URL | syncer-2.0.3.tar.gz |
|---|---|
| Size | 11.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4340eb54b54368724a78c5c0763824470201804fe9180129daf3635cb500550f
|
|
BLAKE2b-256 checksum How to use checksums |
8dddd4dd75843692690d81f0a4b929212a1614b25d4896aa7c72f4c3546c7e3d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.3
|
Security for syncer 2.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.