diff --git a/src/python/grpcio/grpc/BUILD.bazel b/src/python/grpcio/grpc/BUILD.bazel index 470b11e7fd7..f2097cbbf2c 100644 --- a/src/python/grpcio/grpc/BUILD.bazel +++ b/src/python/grpcio/grpc/BUILD.bazel @@ -66,6 +66,11 @@ py_library( srcs = ["_simple_stubs.py"], ) +py_library( + name = "aio", + srcs = glob(["aio/**/*.py"]), +) + py_library( name = "grpcio", srcs = ["__init__.py"], @@ -74,6 +79,7 @@ py_library( ], imports = ["../"], deps = [ + ":aio", ":utilities", ":auth", ":plugin_wrapping", diff --git a/src/python/grpcio/grpc/aio/__init__.py b/src/python/grpcio/grpc/aio/__init__.py new file mode 100644 index 00000000000..2933aa5a45e --- /dev/null +++ b/src/python/grpcio/grpc/aio/__init__.py @@ -0,0 +1,81 @@ +# Copyright 2019 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""gRPC's Asynchronous Python API. + +gRPC Async API objects may only be used on the thread on which they were +created. AsyncIO doesn't provide thread safety for most of its APIs. +""" + +from typing import Any, Optional, Sequence, Tuple + +import grpc +from grpc._cython.cygrpc import (init_grpc_aio, shutdown_grpc_aio, EOF, + AbortError, BaseError, InternalError, + UsageError) + +from ._base_call import (Call, RpcContext, StreamStreamCall, StreamUnaryCall, + UnaryStreamCall, UnaryUnaryCall) +from ._base_channel import (Channel, StreamStreamMultiCallable, + StreamUnaryMultiCallable, UnaryStreamMultiCallable, + UnaryUnaryMultiCallable) +from ._call import AioRpcError +from ._interceptor import (ClientCallDetails, ClientInterceptor, + InterceptedUnaryUnaryCall, + UnaryUnaryClientInterceptor, + UnaryStreamClientInterceptor, + StreamUnaryClientInterceptor, + StreamStreamClientInterceptor, ServerInterceptor) +from ._server import server +from ._base_server import Server, ServicerContext +from ._typing import ChannelArgumentType +from ._channel import insecure_channel, secure_channel +from ._metadata import Metadata + +################################### __all__ ################################# + +__all__ = ( + 'init_grpc_aio', + 'shutdown_grpc_aio', + 'AioRpcError', + 'RpcContext', + 'Call', + 'UnaryUnaryCall', + 'UnaryStreamCall', + 'StreamUnaryCall', + 'StreamStreamCall', + 'Channel', + 'UnaryUnaryMultiCallable', + 'UnaryStreamMultiCallable', + 'StreamUnaryMultiCallable', + 'StreamStreamMultiCallable', + 'ClientCallDetails', + 'ClientInterceptor', + 'UnaryStreamClientInterceptor', + 'UnaryUnaryClientInterceptor', + 'StreamUnaryClientInterceptor', + 'StreamStreamClientInterceptor', + 'InterceptedUnaryUnaryCall', + 'ServerInterceptor', + 'insecure_channel', + 'server', + 'Server', + 'ServicerContext', + 'EOF', + 'secure_channel', + 'AbortError', + 'BaseError', + 'UsageError', + 'InternalError', + 'Metadata', +) diff --git a/src/python/grpcio/grpc/experimental/aio/_base_call.py b/src/python/grpcio/grpc/aio/_base_call.py similarity index 100% rename from src/python/grpcio/grpc/experimental/aio/_base_call.py rename to src/python/grpcio/grpc/aio/_base_call.py diff --git a/src/python/grpcio/grpc/experimental/aio/_base_channel.py b/src/python/grpcio/grpc/aio/_base_channel.py similarity index 100% rename from src/python/grpcio/grpc/experimental/aio/_base_channel.py rename to src/python/grpcio/grpc/aio/_base_channel.py diff --git a/src/python/grpcio/grpc/experimental/aio/_base_server.py b/src/python/grpcio/grpc/aio/_base_server.py similarity index 100% rename from src/python/grpcio/grpc/experimental/aio/_base_server.py rename to src/python/grpcio/grpc/aio/_base_server.py diff --git a/src/python/grpcio/grpc/experimental/aio/_call.py b/src/python/grpcio/grpc/aio/_call.py similarity index 100% rename from src/python/grpcio/grpc/experimental/aio/_call.py rename to src/python/grpcio/grpc/aio/_call.py diff --git a/src/python/grpcio/grpc/experimental/aio/_channel.py b/src/python/grpcio/grpc/aio/_channel.py similarity index 100% rename from src/python/grpcio/grpc/experimental/aio/_channel.py rename to src/python/grpcio/grpc/aio/_channel.py diff --git a/src/python/grpcio/grpc/experimental/aio/_interceptor.py b/src/python/grpcio/grpc/aio/_interceptor.py similarity index 100% rename from src/python/grpcio/grpc/experimental/aio/_interceptor.py rename to src/python/grpcio/grpc/aio/_interceptor.py diff --git a/src/python/grpcio/grpc/experimental/aio/_metadata.py b/src/python/grpcio/grpc/aio/_metadata.py similarity index 100% rename from src/python/grpcio/grpc/experimental/aio/_metadata.py rename to src/python/grpcio/grpc/aio/_metadata.py diff --git a/src/python/grpcio/grpc/experimental/aio/_server.py b/src/python/grpcio/grpc/aio/_server.py similarity index 100% rename from src/python/grpcio/grpc/experimental/aio/_server.py rename to src/python/grpcio/grpc/aio/_server.py diff --git a/src/python/grpcio/grpc/experimental/aio/_typing.py b/src/python/grpcio/grpc/aio/_typing.py similarity index 100% rename from src/python/grpcio/grpc/experimental/aio/_typing.py rename to src/python/grpcio/grpc/aio/_typing.py diff --git a/src/python/grpcio/grpc/experimental/aio/_utils.py b/src/python/grpcio/grpc/aio/_utils.py similarity index 100% rename from src/python/grpcio/grpc/experimental/aio/_utils.py rename to src/python/grpcio/grpc/aio/_utils.py diff --git a/src/python/grpcio/grpc/experimental/__init__.py b/src/python/grpcio/grpc/experimental/__init__.py index 1ca0e7005c4..a4e2660fb4e 100644 --- a/src/python/grpcio/grpc/experimental/__init__.py +++ b/src/python/grpcio/grpc/experimental/__init__.py @@ -122,6 +122,6 @@ __all__ = ( 'wrap_server_method_handler', ) -if sys.version_info[0] == 3 and sys.version_info[1] >= 6: +if sys.version_info > (3, 6): from grpc._simple_stubs import unary_unary, unary_stream, stream_unary, stream_stream __all__ = __all__ + (unary_unary, unary_stream, stream_unary, stream_stream) diff --git a/src/python/grpcio/grpc/experimental/aio/__init__.py b/src/python/grpcio/grpc/experimental/aio/__init__.py index 2933aa5a45e..576cb8dcde4 100644 --- a/src/python/grpcio/grpc/experimental/aio/__init__.py +++ b/src/python/grpcio/grpc/experimental/aio/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2019 gRPC authors. +# Copyright 2020 The gRPC Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,71 +11,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -"""gRPC's Asynchronous Python API. +"""Alias of grpc.aio to keep backward compatibility.""" -gRPC Async API objects may only be used on the thread on which they were -created. AsyncIO doesn't provide thread safety for most of its APIs. -""" - -from typing import Any, Optional, Sequence, Tuple - -import grpc -from grpc._cython.cygrpc import (init_grpc_aio, shutdown_grpc_aio, EOF, - AbortError, BaseError, InternalError, - UsageError) - -from ._base_call import (Call, RpcContext, StreamStreamCall, StreamUnaryCall, - UnaryStreamCall, UnaryUnaryCall) -from ._base_channel import (Channel, StreamStreamMultiCallable, - StreamUnaryMultiCallable, UnaryStreamMultiCallable, - UnaryUnaryMultiCallable) -from ._call import AioRpcError -from ._interceptor import (ClientCallDetails, ClientInterceptor, - InterceptedUnaryUnaryCall, - UnaryUnaryClientInterceptor, - UnaryStreamClientInterceptor, - StreamUnaryClientInterceptor, - StreamStreamClientInterceptor, ServerInterceptor) -from ._server import server -from ._base_server import Server, ServicerContext -from ._typing import ChannelArgumentType -from ._channel import insecure_channel, secure_channel -from ._metadata import Metadata - -################################### __all__ ################################# - -__all__ = ( - 'init_grpc_aio', - 'shutdown_grpc_aio', - 'AioRpcError', - 'RpcContext', - 'Call', - 'UnaryUnaryCall', - 'UnaryStreamCall', - 'StreamUnaryCall', - 'StreamStreamCall', - 'Channel', - 'UnaryUnaryMultiCallable', - 'UnaryStreamMultiCallable', - 'StreamUnaryMultiCallable', - 'StreamStreamMultiCallable', - 'ClientCallDetails', - 'ClientInterceptor', - 'UnaryStreamClientInterceptor', - 'UnaryUnaryClientInterceptor', - 'StreamUnaryClientInterceptor', - 'StreamStreamClientInterceptor', - 'InterceptedUnaryUnaryCall', - 'ServerInterceptor', - 'insecure_channel', - 'server', - 'Server', - 'ServicerContext', - 'EOF', - 'secure_channel', - 'AbortError', - 'BaseError', - 'UsageError', - 'InternalError', - 'Metadata', -) +from grpc.aio import * diff --git a/src/python/grpcio_tests/tests_aio/unit/_common.py b/src/python/grpcio_tests/tests_aio/unit/_common.py index 7fdd120e31b..016280a1528 100644 --- a/src/python/grpcio_tests/tests_aio/unit/_common.py +++ b/src/python/grpcio_tests/tests_aio/unit/_common.py @@ -16,8 +16,8 @@ import asyncio import grpc from typing import AsyncIterable from grpc.experimental import aio -from grpc.experimental.aio._typing import MetadatumType, MetadataKey, MetadataValue -from grpc.experimental.aio._metadata import Metadata +from grpc.aio._typing import MetadatumType, MetadataKey, MetadataValue +from grpc.aio._metadata import Metadata from tests.unit.framework.common import test_constants diff --git a/src/python/grpcio_tests/tests_aio/unit/aio_rpc_error_test.py b/src/python/grpcio_tests/tests_aio/unit/aio_rpc_error_test.py index 416c51a7080..b7b18e08f6e 100644 --- a/src/python/grpcio_tests/tests_aio/unit/aio_rpc_error_test.py +++ b/src/python/grpcio_tests/tests_aio/unit/aio_rpc_error_test.py @@ -19,7 +19,7 @@ import unittest import grpc from grpc.experimental import aio -from grpc.experimental.aio._call import AioRpcError +from grpc.aio._call import AioRpcError from tests_aio.unit._test_base import AioTestBase _TEST_INITIAL_METADATA = aio.Metadata( diff --git a/src/python/grpcio_tests/tests_aio/unit/close_channel_test.py b/src/python/grpcio_tests/tests_aio/unit/close_channel_test.py index 1e10074c47c..20543e95bf7 100644 --- a/src/python/grpcio_tests/tests_aio/unit/close_channel_test.py +++ b/src/python/grpcio_tests/tests_aio/unit/close_channel_test.py @@ -19,7 +19,7 @@ import unittest import grpc from grpc.experimental import aio -from grpc.experimental.aio import _base_call +from grpc.aio import _base_call from src.proto.grpc.testing import messages_pb2, test_pb2_grpc from tests_aio.unit._test_base import AioTestBase