What are the differences between Python Playwright sync vs. async APIs?

Question:

I’ve started learning playwright-python and the package playwright has the two submodules async_api and sync_api. However I could not find any deeper description or discussion on their respective benefits and drawbacks. From their names I assume that the synchronous API calls are blocking and the asynchronous ones run in the background?

Are they different in their capabilities, i.e. are there scenarios in which the sync_api cannot accomplish something you can do using the async_api (or vice versa)?

Asked By: buddemat

||

Answers:

The sync_api is simply a wrapper around the asyncio_api that abstracts asyncio usage away from you. As such, the capabilities are largely the same, but the async_api may afford some more flexibility in complex scenarios (for example, in previous playwright-python releases the only way to run instances in a multi-threaded fashion on Unix + Python 3.7 was to use the async_api, this is no longer the case, though).

Chances are you won’t need that flexibility though, so I’d just suggest using whatever you’re comfortable with.

Answered By: Mattwmaster58