Skip to content

Commit 30c5b52

Browse files
authored
feat(api): split sync and async entry points (#382)
1 parent 062cc15 commit 30c5b52

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+703
-463
lines changed

buildbots/assets/stub.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from playwright import sync_playwright
1+
from playwright.sync_api import sync_playwright
22

33
with sync_playwright() as p:
44
for browser_type in [p.chromium, p.firefox, p.webkit]:

client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,5 @@ def main(playwright: Playwright) -> None:
8888

8989

9090
if __name__ == "__main__":
91-
with playwright.sync_playwright() as p:
91+
with playwright.sync_api.sync_playwright() as p:
9292
main(p)

playwright/__init__.py

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
1415
"""
1516
Python package `playwright` is a Python library to automate Chromium,
1617
Firefox and WebKit with a single API. Playwright is built to enable cross-browser
@@ -19,50 +20,6 @@
1920
and for the async API [here](async_api.html).
2021
"""
2122

22-
import playwright._api_structures as api_structures
23-
import playwright._api_types as api_types
24-
from playwright._main import AsyncPlaywrightContextManager, SyncPlaywrightContextManager
25-
26-
DeviceDescriptor = api_types.DeviceDescriptor
27-
Error = api_types.Error
28-
FilePayload = api_types.FilePayload
29-
FloatRect = api_types.FloatRect
30-
Geolocation = api_types.Geolocation
31-
PdfMargins = api_types.PdfMargins
32-
ProxySettings = api_types.ProxySettings
33-
SourceLocation = api_types.SourceLocation
34-
TimeoutError = api_types.TimeoutError
35-
36-
Cookie = api_structures.Cookie
37-
ResourceTiming = api_structures.ResourceTiming
38-
StorageState = api_structures.StorageState
39-
40-
41-
def async_playwright() -> AsyncPlaywrightContextManager:
42-
return AsyncPlaywrightContextManager()
43-
44-
45-
def sync_playwright() -> SyncPlaywrightContextManager:
46-
return SyncPlaywrightContextManager()
47-
48-
49-
__all__ = [
50-
"async_playwright",
51-
"sync_playwright",
52-
"Cookie",
53-
"DeviceDescriptor",
54-
"Error",
55-
"FilePayload",
56-
"FloatRect",
57-
"Geolocation",
58-
"PdfMargins",
59-
"ProxySettings",
60-
"ResourceTiming",
61-
"SourceLocation",
62-
"StorageState",
63-
"TimeoutError",
64-
]
65-
6623
__pdoc__ = {
6724
"_accessibility": False,
6825
"_async_base": False,

playwright/__main__.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from playwright._main import main
15+
import os
16+
import subprocess
17+
import sys
1618

17-
main()
19+
from playwright._impl._driver import compute_driver_executable
20+
21+
driver_executable = compute_driver_executable()
22+
my_env = os.environ.copy()
23+
my_env["PW_CLI_TARGET_LANG"] = "python"
24+
subprocess.run([str(driver_executable), *sys.argv[1:]], env=my_env)

playwright/_accessibility.py renamed to playwright/_impl/_accessibility.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
from typing import Dict, Optional
1616

17-
from playwright._connection import Channel
18-
from playwright._element_handle import ElementHandle
19-
from playwright._helper import locals_to_params
17+
from playwright._impl._connection import Channel
18+
from playwright._impl._element_handle import ElementHandle
19+
from playwright._impl._helper import locals_to_params
2020

2121

2222
def _ax_node_from_protocol(axNode: Dict) -> Dict:
File renamed without changes.
File renamed without changes.

playwright/_async_base.py renamed to playwright/_impl/_async_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import asyncio
1616
from typing import Any, Callable, Coroutine, Generic, Optional, TypeVar, cast
1717

18-
from playwright._impl_to_api_mapping import ImplToApiMapping, ImplWrapper
18+
from playwright._impl._impl_to_api_mapping import ImplToApiMapping, ImplWrapper
1919

2020
mapping = ImplToApiMapping()
2121

playwright/_browser.py renamed to playwright/_impl/_browser.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@
1818
from types import SimpleNamespace
1919
from typing import TYPE_CHECKING, Dict, List, Tuple, Union
2020

21-
from playwright._api_structures import StorageState
22-
from playwright._api_types import Geolocation, ProxySettings
23-
from playwright._browser_context import BrowserContext
24-
from playwright._connection import ChannelOwner, from_channel
25-
from playwright._helper import ColorScheme, is_safe_close_error, locals_to_params
26-
from playwright._network import serialize_headers
27-
from playwright._page import Page
21+
from playwright._impl._api_structures import StorageState
22+
from playwright._impl._api_types import Geolocation, ProxySettings
23+
from playwright._impl._browser_context import BrowserContext
24+
from playwright._impl._connection import ChannelOwner, from_channel
25+
from playwright._impl._helper import ColorScheme, is_safe_close_error, locals_to_params
26+
from playwright._impl._network import serialize_headers
27+
from playwright._impl._page import Page
2828

2929
if sys.version_info >= (3, 8): # pragma: no cover
3030
from typing import Literal
3131
else: # pragma: no cover
3232
from typing_extensions import Literal
3333

3434
if TYPE_CHECKING: # pragma: no cover
35-
from playwright._browser_type import BrowserType
35+
from playwright._impl._browser_type import BrowserType
3636

3737

3838
class Browser(ChannelOwner):

playwright/_browser_context.py renamed to playwright/_impl/_browser_context.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
from types import SimpleNamespace
2020
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Union, cast
2121

22-
from playwright._api_structures import Cookie, StorageState
23-
from playwright._api_types import Error
24-
from playwright._connection import ChannelOwner, from_channel
25-
from playwright._event_context_manager import EventContextManagerImpl
26-
from playwright._helper import (
22+
from playwright._impl._api_structures import Cookie, StorageState
23+
from playwright._impl._api_types import Error
24+
from playwright._impl._connection import ChannelOwner, from_channel
25+
from playwright._impl._event_context_manager import EventContextManagerImpl
26+
from playwright._impl._helper import (
2727
PendingWaitEvent,
2828
RouteHandler,
2929
RouteHandlerEntry,
@@ -33,12 +33,12 @@
3333
is_safe_close_error,
3434
locals_to_params,
3535
)
36-
from playwright._network import Request, Route, serialize_headers
37-
from playwright._page import BindingCall, Page
38-
from playwright._wait_helper import WaitHelper
36+
from playwright._impl._network import Request, Route, serialize_headers
37+
from playwright._impl._page import BindingCall, Page
38+
from playwright._impl._wait_helper import WaitHelper
3939

4040
if TYPE_CHECKING: # pragma: no cover
41-
from playwright._browser import Browser
41+
from playwright._impl._browser import Browser
4242

4343

4444
class BrowserContext(ChannelOwner):

0 commit comments

Comments
 (0)