Repository: digital-asset/dazl-client (language: python)

Issue:
python: More improvements on code generated from Protobuf files.
python: More improvements on code generated from Protobuf files:

* add `__all__` declarations to `__init__.py` files that include all of the symbols across all of the module flies in a particular package, as this is not handled by the Python protobuf compiler (see https://github.com/protocolbuffers/protobuf/issues/881)
* drop redundant type declarations for `Message` subclasses, as they are already covered by `types-protobuf`.


Discussion / hints:

Fix patch:
diff --git a/python/dazl/ledger/grpc/channel.py b/python/dazl/ledger/grpc/channel.py
index e42a754a..f9a121c8 100644
--- a/python/dazl/ledger/grpc/channel.py
+++ b/python/dazl/ledger/grpc/channel.py
@@ -1,5 +1,6 @@
 # Copyright (c) 2017-2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
 # SPDX-License-Identifier: Apache-2.0
+
 from typing import List, Tuple, Union, cast
 from urllib.parse import urlparse
 
diff --git a/python/dazl/ledger/grpc/codec_aio.py b/python/dazl/ledger/grpc/codec_aio.py
index a86d630e..ff3d1aec 100644
--- a/python/dazl/ledger/grpc/codec_aio.py
+++ b/python/dazl/ledger/grpc/codec_aio.py
@@ -25,28 +25,8 @@
     ExerciseResponse,
     PartyInfo,
 )
-from ..._gen.com.daml.ledger.api.v1.admin.party_management_service_pb2 import (
-    PartyDetails as G_PartyDetails,
-)
-from ..._gen.com.daml.ledger.api.v1.commands_pb2 import (
-    Command as G_Command,
-    CreateAndExerciseCommand as G_CreateAndExerciseCommand,
-    CreateCommand as G_CreateCommand,
-    ExerciseByKeyCommand as G_ExerciseByKeyCommand,
-    ExerciseCommand as G_ExerciseCommand,
-)
-from ..._gen.com.daml.ledger.api.v1.event_pb2 import (
-    ArchivedEvent as G_ArchivedEvent,
-    CreatedEvent as G_CreatedEvent,
-    ExercisedEvent as G_ExercisedEvent,
-)
-from ..._gen.com.daml.ledger.api.v1.ledger_offset_pb2 import LedgerOffset as G_LedgerOffset
-from ..._gen.com.daml.ledger.api.v1.transaction_filter_pb2 import (
-    Filters as G_Filters,
-    InclusiveFilters as G_InclusiveFilters,
-)
-from ..._gen.com.daml.ledger.api.v1.transaction_pb2 import TransactionTree as G_TransactionTree
-from ..._gen.com.daml.ledger.api.v1.value_pb2 import Identifier as G_Identifier
+from ..._gen.com.daml.ledger.api import v1 as lapipb
+from ..._gen.com.daml.ledger.api.v1 import admin as lapiadminpb
 from ...damlast.daml_lf_1 import (
     DefTemplate,
     DottedName,
@@ -93,23 +73,25 @@ def __init__(self, conn: PackageService, lookup: Optional[MultiPackageLookup] =
     def lookup(self) -> SymbolLookup:
         return self._lookup
 
-    async def encode_command(self, cmd: Command) -> G_Command:
+    async def encode_command(self, cmd: Command) -> lapipb.Command:
         if isinstance(cmd, CreateCommand):
-            return G_Command(create=await self.encode_create_command(cmd.template_id, cmd.payload))
+            return lapipb.Command(
+                create=await self.encode_create_command(cmd.template_id, cmd.payload)
+            )
         elif isinstance(cmd, ExerciseCommand):
-            return G_Command(
+            return lapipb.Command(
                 exercise=await self.encode_exercise_command(
                     cmd.contract_id, cmd.choice, cmd.argument
                 )
             )
         elif isinstance(cmd, ExerciseByKeyCommand):
-            return G_Command(
+            return lapipb.Command(
                 exerciseByKey=await self.encode_exercise_by_key_command(
                     cmd.template_id, cmd.choice, cmd.key, cmd.argument
                 )
             )
         elif isinstance(cmd, CreateAndExerciseCommand):
-            return G_Command(
+            return lapipb.Command(
                 createAndExercise=await self.encode_create_and_exercise_command(
                     cmd.template_id, cmd.payload, cmd.choice, cmd.argument
                 )
@@ -119,12 +101,12 @@ async def encode_command(self, cmd: Command) -> G_Command:
 
     async def encode_create_command(
         self, template_id: Union[str, Any], payload: ContractData
-    ) -> G_CreateCommand:
+    ) -> lapipb.CreateCommand:
         item_type = await self._loader.do_with_retry(
             lambda: self._lookup.template_name(template_id)
         )
         _, value = self._encode_context.convert(con(item_type), payload)
-        return G_CreateCommand(
+        return lapipb.CreateCommand(
             template_id=self.encode_identifier(item_type), create_arguments=value
         )
 
@@ -133,10 +115,10 @@ async def encode_exercise_command(
         contract_id: ContractId,
         choice_name: str,
         argument: Optional[Any] = None,
-    ) -> G_ExerciseCommand:
+    ) -> lapipb.ExerciseCommand:
         item_type, _, choice = await self._look_up_choice(contract_id.value_type, choice_name)
 
-        cmd_pb = G_ExerciseCommand(
+        cmd_pb = lapipb.ExerciseCommand(
             template_id=self.encode_identifier(item_type),
             contract_id=contract_id.value,
             choice=choice_name,
@@ -152,14 +134,14 @@ async def encode_create_and_exercise_command(
         payload: ContractData,
         choice_name: str,
         argument: Optional[Any] = None,
-    ) -> G_CreateAndExerciseCommand:
+    ) -> lapipb.CreateAndExerciseCommand:
         item_type, _, choice = await self._look_up_choice(template_id, choice_name)
 
         payload_field, payload_pb = await self.encode_value(con(item_type), payload)
         if payload_pb != "record":
             raise ValueError("unexpected non-record type when constructing payload")
         argument_field, argument_pb = await self.encode_value(choice.arg_binder.type, argument)
-        cmd_pb = G_CreateAndExerciseCommand(
+        cmd_pb = lapipb.CreateAndExerciseCommand(
             create_arguments=payload_pb,
             template_id=self.encode_identifier(item_type),
             choice=choice_name,
@@ -174,14 +156,14 @@ async def encode_exercise_by_key_command(
         choice_name: str,
         key: Any,
         argument: Optional[ContractData] = None,
-    ) -> G_ExerciseByKeyCommand:
+    ) -> lapipb.ExerciseByKeyCommand:
         item_type, template, choice = await self._look_up_choice(template_id, choice_name)
         if template.key is None:
             raise ValueError(
                 f"cannot encode ExerciseByKeyCommand; template {template_id} does not have a contract key defined"
             )
 
-        cmd_pb = G_ExerciseByKeyCommand(
+        cmd_pb = lapipb.ExerciseByKeyCommand(
             template_id=self.encode_identifier(item_type),
             choice=choice_name,
         )
@@ -192,7 +174,7 @@ async def encode_exercise_by_key_command(
 
         return cmd_pb
 
-    async def encode_filters(self, template_ids: Sequence[TypeConName]) -> G_Filters:
+    async def encode_filters(self, template_ids: Sequence[TypeConName]) -> lapipb.Filters:
         # Search for a reference to the "wildcard" template; if any of the requested template_ids
         # is "*", then return results for all templates. We do this first because resolving template
         # IDs otherwise requires do_with_retry, which can be expensive.
@@ -201,7 +183,7 @@ async def encode_filters(self, template_ids: Sequence[TypeConName]) -> G_Filters
         ):
             # if any of the keys references the "wildcard" template, (or no values were supplied)
             # then this means we need to fetch values for all templates
-            return G_Filters()
+            return lapipb.Filters()
 
         # No wildcard template IDs, so inspect and resolve all template references to concrete
         # template IDs
@@ -211,8 +193,8 @@ async def encode_filters(self, template_ids: Sequence[TypeConName]) -> G_Filters
                 await self._loader.do_with_retry(lambda: self._lookup.template_names(template_id))
             )
 
-        return G_Filters(
-            inclusive=G_InclusiveFilters(
+        return lapipb.Filters(
+            inclusive=lapipb.InclusiveFilters(
                 template_ids=[self.encode_identifier(i) for i in sorted(requested_types)]
             )
         )
@@ -226,18 +208,22 @@ async def encode_value(self, item_type: Type, obj: Any) -> Tuple[str, Optional[A
         )
 
     @staticmethod
-    def encode_identifier(name: TypeConName) -> G_Identifier:
-        return G_Identifier(
+    def encode_identifier(name: TypeConName) -> lapipb.Identifier:
+        return lapipb.Identifier(
             package_id=package_ref(name),
             module_name=str(module_name(name)),
             entity_name=module_local_name(name),
         )
 
     @staticmethod
-    def encode_begin_offset(offset: Optional[str]) -> G_LedgerOffset:
-        return G_LedgerOffset(absolute=offset) if offset is not None else G_LedgerOffset(boundary=0)
+    def encode_begin_offset(offset: Optional[str]) -> lapipb.LedgerOffset:
+        return (
+            lapipb.LedgerOffset(absolute=offset)
+            if offset is not None
+            else lapipb.LedgerOffset(boundary=0)
+        )
 
-    async def decode_created_event(self, event: G_CreatedEvent) -> CreateEvent:
+    async def decode_created_event(self, event: lapipb.CreatedEvent) -> CreateEvent:
         cid = self.decode_contract_id(event)
         cdata = await self.decode_value(con(cid.value_type), event.create_arguments)
         if not isinstance(cdata, _Mapping):
@@ -259,11 +245,11 @@ async def decode_created_event(self, event: G_CreatedEvent) -> CreateEvent:
             key,
         )
 
-    async def decode_archived_event(self, event: G_ArchivedEvent) -> ArchiveEvent:
+    async def decode_archived_event(self, event: lapipb.ArchivedEvent) -> ArchiveEvent:
         cid = self.decode_contract_id(event)
         return ArchiveEvent(cid)
 
-    async def decode_exercise_response(self, tree: G_TransactionTree) -> ExerciseResponse:
+    async def decode_exercise_response(self, tree: lapipb.TransactionTree) -> ExerciseResponse:
         """
         Convert a Protobuf TransactionTree response to an ExerciseResponse. The TransactionTree is
         expected to only contain a single exercise node at the root level.
@@ -309,7 +295,7 @@ async def decode_exercise_response(self, tree: G_TransactionTree) -> ExerciseRes
         return ExerciseResponse(result, events)
 
     async def _decode_exercised_child_events(
-        self, tree: G_TransactionTree, event_ids: Sequence[str]
+        self, tree: lapipb.TransactionTree, event_ids: Sequence[str]
     ) -> Sequence[Union[CreateEvent, ArchiveEvent]]:
         from ... import LOG
 
@@ -340,13 +326,13 @@ async def decode_value(self, item_type: Type, obj: Any) -> Optional[Any]:
         )
 
     def decode_contract_id(
-        self, event: Union[G_CreatedEvent, G_ExercisedEvent, G_ArchivedEvent]
+        self, event: Union[lapipb.CreatedEvent, lapipb.ExercisedEvent, lapipb.ArchivedEvent]
     ) -> ContractId:
         vt = Codec.decode_identifier(event.template_id)
         return self._decode_context.convert(ContractIdType(con(vt)), event.contract_id)
 
     @staticmethod
-    def decode_identifier(identifier: G_Identifier) -> TypeConName:
+    def decode_identifier(identifier: lapipb.Identifier) -> TypeConName:
         return TypeConName(
             ModuleRef(
                 PackageRef(identifier.package_id), DottedName(identifier.module_name.split("."))
@@ -355,7 +341,7 @@ def decode_identifier(identifier: G_Identifier) -> TypeConName:
         )
 
     @staticmethod
-    def decode_party_info(party_details: G_PartyDetails) -> PartyInfo:
+    def decode_party_info(party_details: lapiadminpb.PartyDetails) -> PartyInfo:
         return PartyInfo(
             Party(party_details.party), party_details.display_name, party_details.is_local
         )
diff --git a/python/dazl/ledger/grpc/conn_aio.py b/python/dazl/ledger/grpc/conn_aio.py
index 182cd9a2..391dc638 100644
--- a/python/dazl/ledger/grpc/conn_aio.py
+++ b/python/dazl/ledger/grpc/conn_aio.py
@@ -13,48 +13,8 @@
 from grpc.aio import Channel, UnaryStreamCall
 
 from .. import aio
-from ..._gen.com.daml.ledger.api.v1.active_contracts_service_pb2 import (
-    GetActiveContractsRequest as G_GetActiveContractsRequest,
-)
-from ..._gen.com.daml.ledger.api.v1.active_contracts_service_pb2_grpc import (
-    ActiveContractsServiceStub,
-)
-from ..._gen.com.daml.ledger.api.v1.admin.package_management_service_pb2 import (
-    UploadDarFileRequest as G_UploadDarFileRequest,
-)
-from ..._gen.com.daml.ledger.api.v1.admin.package_management_service_pb2_grpc import (
-    PackageManagementServiceStub,
-)
-from ..._gen.com.daml.ledger.api.v1.admin.party_management_service_pb2 import (
-    AllocatePartyRequest as G_AllocatePartyRequest,
-    ListKnownPartiesRequest as G_ListKnownPartiesRequest,
-)
-from ..._gen.com.daml.ledger.api.v1.admin.party_management_service_pb2_grpc import (
-    PartyManagementServiceStub,
-)
-from ..._gen.com.daml.ledger.api.v1.command_service_pb2 import (
-    SubmitAndWaitRequest as G_SubmitAndWaitRequest,
-)
-from ..._gen.com.daml.ledger.api.v1.command_service_pb2_grpc import CommandServiceStub
-from ..._gen.com.daml.ledger.api.v1.commands_pb2 import Command as G_Command, Commands as G_Commands
-from ..._gen.com.daml.ledger.api.v1.ledger_identity_service_pb2 import (
-    GetLedgerIdentityRequest as G_GetLedgerIdentityRequest,
-)
-from ..._gen.com.daml.ledger.api.v1.ledger_identity_service_pb2_grpc import (
-    LedgerIdentityServiceStub,
-)
-from ..._gen.com.daml.ledger.api.v1.package_service_pb2 import (
-    GetPackageRequest as G_GetPackageRequest,
-    ListPackagesRequest as G_ListPackagesRequest,
-)
-from ..._gen.com.daml.ledger.api.v1.package_service_pb2_grpc import PackageServiceStub
-from ..._gen.com.daml.ledger.api.v1.transaction_filter_pb2 import (
-    TransactionFilter as G_TransactionFilter,
-)
-from ..._gen.com.daml.ledger.api.v1.transaction_service_pb2 import (
-    GetTransactionsRequest as G_GetTransactionsRequest,
-)
-from ..._gen.com.daml.ledger.api.v1.transaction_service_pb2_grpc import TransactionServiceStub
+from ..._gen.com.daml.ledger.api import v1 as lapipb
+from ..._gen.com.daml.ledger.api.v1 import admin as lapiadminpb
 from ...damlast.daml_lf_1 import PackageRef, TypeConName
 from ...damlast.util import is_match
 from ...prim import LEDGER_STRING_REGEX, ContractData, ContractId, Party
@@ -117,8 +77,8 @@ async def open(self) -> None:
         if not self._config.access.ledger_id:
             # most calls require a ledger ID; if it wasn't supplied as part of our token or we were
             # never given a token in the first place, fetch the ledger ID from the destination
-            stub = LedgerIdentityServiceStub(self._channel)
-            response = await stub.GetLedgerIdentity(G_GetLedgerIdentityRequest())
+            stub = lapipb.LedgerIdentityServiceStub(self._channel)
+            response = await stub.GetLedgerIdentity(lapipb.GetLedgerIdentityRequest())
             if isinstance(self._config.access, PropertyBasedAccessConfig):
                 self._logger.info("Connected to gRPC Ledger API, ledger ID: %s", response.ledger_id)
                 self._config.access.ledger_id = response.ledger_id
@@ -159,11 +119,11 @@ async def submit(
         elif isinstance(__commands, Command):
             __commands = [__commands]
 
-        stub = CommandServiceStub(self.channel)
+        stub = lapipb.CommandServiceStub(self.channel)
 
         commands_pb = await asyncio.gather(*map(self._codec.encode_command, __commands))
-        request = G_SubmitAndWaitRequest(
-            commands=G_Commands(
+        request = lapipb.SubmitAndWaitRequest(
+            commands=lapipb.Commands(
                 ledger_id=self._config.access.ledger_id,
                 application_id=self._config.access.application_name,
                 command_id=self._command_id(command_id),
@@ -204,13 +164,13 @@ async def create(
         :return:
             The :class:`CreateEvent` that represents the contract that was successfully created.
         """
-        stub = CommandServiceStub(self.channel)
+        stub = lapipb.CommandServiceStub(self.channel)
 
         commands = [
-            G_Command(create=await self._codec.encode_create_command(__template_id, __payload))
+            lapipb.Command(create=await self._codec.encode_create_command(__template_id, __payload))
         ]
-        request = G_SubmitAndWaitRequest(
-            commands=G_Commands(
+        request = lapipb.SubmitAndWaitRequest(
+            commands=lapipb.Commands(
                 ledger_id=self._config.access.ledger_id,
                 application_id=self._config.access.application_name,
                 command_id=self._command_id(command_id),
@@ -260,10 +220,10 @@ async def exercise(
             The return value of the choice, together with a list of events that occurred as a result
             of exercising the choice.
         """
-        stub = CommandServiceStub(self.channel)
+        stub = lapipb.CommandServiceStub(self.channel)
 
         commands = [
-            G_Command(
+            lapipb.Command(
                 exercise=await self._codec.encode_exercise_command(
                     __contract_id, __choice_name, __argument
                 )
@@ -316,10 +276,10 @@ async def create_and_exercise(
             The return value of the choice, together with a list of events that occurred as a result
             of exercising the choice.
         """
-        stub = CommandServiceStub(self.channel)
+        stub = lapipb.CommandServiceStub(self.channel)
 
         commands = [
-            G_Command(
+            lapipb.Command(
                 createAndExercise=await self._codec.encode_create_and_exercise_command(
                     __template_id, __payload, __choice_name, __argument
                 )
@@ -371,10 +331,10 @@ async def exercise_by_key(
             The return value of the choice, together with a list of events that occurred as a result
             of exercising the choice.
         """
-        stub = CommandServiceStub(self.channel)
+        stub = lapipb.CommandServiceStub(self.channel)
 
         commands = [
-            G_Command(
+            lapipb.Command(
                 exerciseByKey=await self._codec.encode_exercise_by_key_command(
                     __template_id, __choice_name, __key, __argument
                 )
@@ -473,12 +433,12 @@ def _command_id(command_id: Optional[str]) -> str:
 
     def _submit_and_wait_request(
         self,
-        commands: Collection[G_Command],
+        commands: Collection[lapipb.Command],
         workflow_id: Optional[str] = None,
         command_id: Optional[str] = None,
-    ) -> G_SubmitAndWaitRequest:
-        return G_SubmitAndWaitRequest(
-            commands=G_Commands(
+    ) -> lapipb.SubmitAndWaitRequest:
+        return lapipb.SubmitAndWaitRequest(
+            commands=lapipb.Commands(
                 ledger_id=self._config.access.ledger_id,
                 application_id=self._config.access.application_name,
                 command_id=self._command_id(command_id),
@@ -592,8 +552,8 @@ async def allocate_party(
         """
         Allocate a new party.
         """
-        stub = PartyManagementServiceStub(self.channel)
-        request = G_AllocatePartyRequest(
+        stub = lapiadminpb.PartyManagementServiceStub(self.channel)
+        request = lapiadminpb.AllocatePartyRequest(
             party_id_hint=Party(identifier_hint) if identifier_hint else None,
             display_name=display_name,
         )
@@ -601,8 +561,8 @@ async def allocate_party(
         return Codec.decode_party_info(response.party_details)
 
     async def list_known_parties(self) -> Sequence[PartyInfo]:
-        stub = PartyManagementServiceStub(self.channel)
-        request = G_ListKnownPartiesRequest()
+        stub = lapiadminpb.PartyManagementServiceStub(self.channel)
+        request = lapiadminpb.ListKnownPartiesRequest()
         response = await stub.ListKnownParties(request)
         return [Codec.decode_party_info(pd) for pd in response.party_details]
 
@@ -611,22 +571,22 @@ async def list_known_parties(self) -> Sequence[PartyInfo]:
     # region Package Management calls
 
     async def get_package(self, package_id: PackageRef) -> bytes:
-        stub = PackageServiceStub(self.channel)
-        request = G_GetPackageRequest(
+        stub = lapipb.PackageServiceStub(self.channel)
+        request = lapipb.GetPackageRequest(
             ledger_id=self._config.access.ledger_id, package_id=package_id
         )
         response = await stub.GetPackage(request)
         return response.archive_payload
 
     async def list_package_ids(self) -> AbstractSet[PackageRef]:
-        stub = PackageServiceStub(self.channel)
-        request = G_ListPackagesRequest(ledger_id=self._config.access.ledger_id)
+        stub = lapipb.PackageServiceStub(self.channel)
+        request = lapipb.ListPackagesRequest(ledger_id=self._config.access.ledger_id)
         response = await stub.ListPackages(request)
         return frozenset({PackageRef(pkg_id) for pkg_id in response.package_ids})
 
     async def upload_package(self, contents: bytes) -> None:
-        stub = PackageManagementServiceStub(self.channel)
-        request = G_UploadDarFileRequest(dar_file=contents)
+        stub = lapiadminpb.PackageManagementServiceStub(self.channel)
+        request = lapiadminpb.UploadDarFileRequest(dar_file=contents)
         await stub.UploadDarFile(request)
         return
 
@@ -681,7 +641,7 @@ async def items(self):
         async with _translate_exceptions(self.conn), self, _allow_cancel(lambda: self._closed):
             filters = await self.conn.codec.encode_filters(self._filters)
             filters_by_party = {party: filters for party in self.conn.config.access.read_as}
-            tx_filter_pb = G_TransactionFilter(filters_by_party=filters_by_party)
+            tx_filter_pb = lapipb.TransactionFilter(filters_by_party=filters_by_party)
 
             offset = None
             if self._offset_range.begin is None:
@@ -725,11 +685,11 @@ async def items(self):
                 )
 
     async def _acs_events(
-        self, filter_pb: G_TransactionFilter
+        self, filter_pb: lapipb.TransactionFilter
     ) -> AsyncIterable[Union[CreateEvent, Boundary]]:
-        stub = ActiveContractsServiceStub(self.conn.channel)
+        stub = lapipb.ActiveContractsServiceStub(self.conn.channel)
 
-        request = G_GetActiveContractsRequest(
+        request = lapipb.GetActiveContractsRequest(
             ledger_id=self.conn.config.access.ledger_id, filter=filter_pb
         )
         self._response_stream = response_stream = stub.GetActiveContracts(request)
@@ -745,11 +705,11 @@ async def _acs_events(
         yield Boundary(offset)
 
     async def _tx_events(
-        self, filter_pb: G_TransactionFilter, begin_offset: Optional[str]
+        self, filter_pb: lapipb.TransactionFilter, begin_offset: Optional[str]
     ) -> AsyncIterable[Union[CreateEvent, ArchiveEvent, Boundary]]:
-        stub = TransactionServiceStub(self.conn.channel)
+        stub = lapipb.TransactionServiceStub(self.conn.channel)
 
-        request = G_GetTransactionsRequest(
+        request = lapipb.GetTransactionsRequest(
             ledger_id=self.conn.config.access.ledger_id,
             filter=filter_pb,
             begin=self.conn.codec.encode_begin_offset(begin_offset),
diff --git a/python/dazl/protocols/_base.py b/python/dazl/protocols/_base.py
index c86366d6..1b4e98e3 100644
--- a/python/dazl/protocols/_base.py
+++ b/python/dazl/protocols/_base.py
@@ -12,10 +12,7 @@
 from typing import TYPE_CHECKING, Optional, Sequence, Union
 
 from .. import LOG
-from .._gen.com.daml.ledger.api.v1.transaction_pb2 import (
-    Transaction as G_Transaction,
-    TransactionTree as G_TransactionTree,
-)
+from .._gen.com.daml.ledger.api import v1 as lapipb
 from ..damlast.lookup import MultiPackageLookup
 from ..prim import Party
 from ..scheduler import Invoker
@@ -114,7 +111,7 @@ async def commands(self, command_payload: "CommandPayload") -> None:
         """
         raise NotImplementedError("commands must be implemented")
 
-    async def commands_transaction(self, __1: "CommandPayload") -> G_Transaction:
+    async def commands_transaction(self, __1: "CommandPayload") -> "lapipb.Transaction":
         """
         Submit a command to the ledger and retrieve the resulting transaction.
 
@@ -125,7 +122,7 @@ async def commands_transaction(self, __1: "CommandPayload") -> G_Transaction:
         """
         raise NotImplementedError("commands_transaction must be implemented")
 
-    async def commands_transaction_tree(self, __1: "CommandPayload") -> G_TransactionTree:
+    async def commands_transaction_tree(self, __1: "CommandPayload") -> "lapipb.TransactionTree":
         """
         Submit a command to the ledger and retrieve the resulting transaction tree.
 
diff --git a/python/dazl/protocols/v1/grpc.py b/python/dazl/protocols/v1/grpc.py
index 26eb6d50..1c767c2b 100644
--- a/python/dazl/protocols/v1/grpc.py
+++ b/python/dazl/protocols/v1/grpc.py
@@ -21,49 +21,8 @@
 )
 
 from ... import LOG
-from ..._gen.com.daml.ledger.api.v1.active_contracts_service_pb2_grpc import (
-    ActiveContractsServiceStub as G_ActiveContractsServiceStub,
-)
-from ..._gen.com.daml.ledger.api.v1.admin.package_management_service_pb2 import (
-    UploadDarFileRequest as G_UploadDarFileRequest,
-)
-from ..._gen.com.daml.ledger.api.v1.admin.package_management_service_pb2_grpc import (
-    PackageManagementServiceStub as G_PackageManagementServiceStub,
-)
-from ..._gen.com.daml.ledger.api.v1.command_service_pb2_grpc import (
-    CommandServiceStub as G_CommandServiceStub,
-)
-from ..._gen.com.daml.ledger.api.v1.ledger_identity_service_pb2 import (
-    GetLedgerIdentityRequest as G_GetLedgerIdentityRequest,
-)
-from ..._gen.com.daml.ledger.api.v1.ledger_identity_service_pb2_grpc import (
-    LedgerIdentityServiceStub as G_LedgerIdentityServiceStub,
-)
-from ..._gen.com.daml.ledger.api.v1.package_service_pb2 import (
-    GetPackageRequest as G_GetPackageRequest,
-    ListPackagesRequest as G_ListPackagesRequest,
-)
-from ..._gen.com.daml.ledger.api.v1.package_service_pb2_grpc import (
-    PackageServiceStub as G_PackageServiceStub,
-)
-from ..._gen.com.daml.ledger.api.v1.testing.time_service_pb2 import (
-    GetTimeRequest as G_GetTimeRequest,
-    SetTimeRequest as G_SetTimeRequest,
-)
-from ..._gen.com.daml.ledger.api.v1.testing.time_service_pb2_grpc import (
-    TimeServiceStub as G_TimeServiceStub,
-)
-from ..._gen.com.daml.ledger.api.v1.transaction_pb2 import (
-    Transaction as G_Transaction,
-    TransactionTree as G_TransactionTree,
-)
-from ..._gen.com.daml.ledger.api.v1.transaction_service_pb2 import (
-    GetLedgerEndRequest as G_GetLedgerEndRequest,
-    GetTransactionTreesResponse as G_GetTransactionTreesResponse,
-)
-from ..._gen.com.daml.ledger.api.v1.transaction_service_pb2_grpc import (
-    TransactionServiceStub as G_TransactionServiceStub,
-)
+from ..._gen.com.daml.ledger.api import v1 as lapipb
+from ..._gen.com.daml.ledger.api.v1 import admin as lapiadminpb, testing as lapitestingpb
 from ...damlast.daml_lf_1 import PackageRef
 from ...damlast.parse import parse_archive_payload
 from ...ledger.aio.pkgloader_compat import PackageLoader
@@ -121,7 +80,7 @@ async def commands(self, command_payload: "CommandPayload") -> None:
         )
         return None
 
-    async def commands_transaction(self, __1: "CommandPayload") -> G_Transaction:
+    async def commands_transaction(self, __1: "CommandPayload") -> lapipb.Transaction:
         from .pb_ser_command import ProtobufSerializer
 
         serializer = cast(ProtobufSerializer, self.ledger.serializer)
@@ -131,7 +90,7 @@ async def commands_transaction(self, __1: "CommandPayload") -> G_Transaction:
         )
         return response.transaction
 
-    async def commands_transaction_tree(self, __1: "CommandPayload") -> G_TransactionTree:
+    async def commands_transaction_tree(self, __1: "CommandPayload") -> lapipb.TransactionTree:
         from .pb_ser_command import ProtobufSerializer
 
         serializer = cast(ProtobufSerializer, self.ledger.serializer)
@@ -201,7 +160,7 @@ async def events(self, transaction_filter: "TransactionFilter") -> "Sequence[Bas
             lambda: self.connection.transaction_service.GetTransactions(request)
         )
 
-        tt_stream = None  # type: Optional[Iterable[G_GetTransactionTreesResponse]]
+        tt_stream = None  # type: Optional[Iterable[lapipb.GetTransactionTreesResponse]]
         if transaction_filter.templates is None:
             # Filtering by package must disable the ability to handle exercise nodes; we may want to
             # consider dropping client-side support for exercise events anyway because they are not
@@ -219,18 +178,18 @@ async def events(self, transaction_filter: "TransactionFilter") -> "Sequence[Bas
         )
 
     async def events_end(self) -> str:
-        request = G_GetLedgerEndRequest(ledger_id=self.ledger.ledger_id)
+        request = lapipb.GetLedgerEndRequest(ledger_id=self.ledger.ledger_id)
         return await self.connection.invoker.run_in_executor(
             lambda: self.connection.transaction_service.GetLedgerEnd(request).offset.absolute
         )
 
 
 def grpc_set_time(connection: "GRPCv1Connection", ledger_id: str, new_datetime: datetime) -> None:
-    get_request = G_GetTimeRequest(ledger_id=ledger_id)
+    get_request = lapitestingpb.GetTimeRequest(ledger_id=ledger_id)
     get_response = connection.time_service.GetTime(get_request)
     ts = next(iter(get_response))
 
-    set_request = G_SetTimeRequest(
+    set_request = lapitestingpb.SetTimeRequest(
         ledger_id=ledger_id,
         current_time=ts.current_time,
         new_time=datetime_to_timestamp(new_datetime),
@@ -240,7 +199,7 @@ def grpc_set_time(connection: "GRPCv1Connection", ledger_id: str, new_datetime:
 
 
 def grpc_upload_package(connection: "GRPCv1Connection", dar_contents: bytes) -> None:
-    request = G_UploadDarFileRequest(dar_file=dar_contents)
+    request = lapiadminpb.UploadDarFileRequest(dar_file=dar_contents)
     connection.package_management_service.UploadDarFile(request)
 
 
@@ -270,7 +229,7 @@ def grpc_detect_ledger_id(connection: "GRPCv1Connection") -> str:
 
         try:
             response = connection.ledger_identity_service.GetLedgerIdentity(
-                G_GetLedgerIdentityRequest()
+                lapipb.GetLedgerIdentityRequest()
             )
         except RpcError as ex:
             details_str = ex.details()
@@ -346,12 +305,12 @@ def __init__(self, connection: "GRPCv1Connection", ledger_id: str):
         self.ledger_id = ledger_id
 
     def package_ids(self) -> "AbstractSet[PackageRef]":
-        request = G_ListPackagesRequest(ledger_id=self.ledger_id)
+        request = lapipb.ListPackagesRequest(ledger_id=self.ledger_id)
         response = self.connection.package_service.ListPackages(request)
         return frozenset([PackageRef(p) for p in response.package_ids])
 
     def package_bytes(self, package_id: "PackageRef") -> bytes:
-        request = G_GetPackageRequest(ledger_id=self.ledger_id, package_id=package_id)
+        request = lapipb.GetPackageRequest(ledger_id=self.ledger_id, package_id=package_id)
         package_info = self.connection.package_service.GetPackage(request)
         return package_info.archive_payload
 
@@ -495,13 +454,13 @@ def __init__(
         super(GRPCv1Connection, self).__init__(invoker, options, settings, context_path)
         self._closed = Event()
         self._channel = grpc_create_channel(settings)
-        self.active_contract_set_service = G_ActiveContractsServiceStub(self._channel)
-        self.command_service = G_CommandServiceStub(self._channel)
-        self.transaction_service = G_TransactionServiceStub(self._channel)
-        self.package_service = G_PackageServiceStub(self._channel)
-        self.package_management_service = G_PackageManagementServiceStub(self._channel)
-        self.ledger_identity_service = G_LedgerIdentityServiceStub(self._channel)
-        self.time_service = G_TimeServiceStub(self._channel)
+        self.active_contract_set_service = lapipb.ActiveContractsServiceStub(self._channel)
+        self.command_service = lapipb.CommandServiceStub(self._channel)
+        self.transaction_service = lapipb.TransactionServiceStub(self._channel)
+        self.package_service = lapipb.PackageServiceStub(self._channel)
+        self.package_management_service = lapiadminpb.PackageManagementServiceStub(self._channel)
+        self.ledger_identity_service = lapipb.LedgerIdentityServiceStub(self._channel)
+        self.time_service = lapitestingpb.TimeServiceStub(self._channel)
 
     def close(self):
         try:
diff --git a/python/dazl/protocols/v1/pb_parse_event.py b/python/dazl/protocols/v1/pb_parse_event.py
index 4e494fcb..0cb4b8ac 100644
--- a/python/dazl/protocols/v1/pb_parse_event.py
+++ b/python/dazl/protocols/v1/pb_parse_event.py
@@ -10,15 +10,7 @@
 import warnings
 
 from ... import LOG
-from ..._gen.com.daml.ledger.api.v1 import (
-    active_contracts_service_pb2 as acs_pb2,
-    event_pb2,
-    ledger_offset_pb2 as lo_pb2,
-    transaction_filter_pb2 as txf_pb2,
-    transaction_pb2 as tx_pb2,
-    transaction_service_pb2 as txs_pb2,
-    value_pb2,
-)
+from ..._gen.com.daml.ledger.api import v1 as lapipb
 from ...damlast.daml_lf_1 import TypeConName
 from ...damlast.daml_types import con
 from ...damlast.lookup import find_choice
@@ -245,22 +237,22 @@ def contract_archived_event(
 
 def serialize_transactions_request(
     f: "TransactionFilter", ledger_id: str, party: Party
-) -> "txs_pb2.GetTransactionsRequest":
+) -> "lapipb.GetTransactionsRequest":
     if f.current_offset is not None:
-        ledger_offset = lo_pb2.LedgerOffset()
+        ledger_offset = lapipb.LedgerOffset()
         ledger_offset.absolute = f.current_offset
     else:
-        ledger_offset = lo_pb2.LedgerOffset()
+        ledger_offset = lapipb.LedgerOffset()
         ledger_offset.boundary = 0
 
     if f.destination_offset is not None:
-        final_offset = lo_pb2.LedgerOffset()
+        final_offset = lapipb.LedgerOffset()
         final_offset.absolute = f.destination_offset
     else:
-        final_offset = lo_pb2.LedgerOffset()
+        final_offset = lapipb.LedgerOffset()
         final_offset.boundary = 1
 
-    return txs_pb2.GetTransactionsRequest(
+    return lapipb.GetTransactionsRequest(
         ledger_id=ledger_id,
         begin=ledger_offset,
         end=final_offset,
@@ -270,23 +262,23 @@ def serialize_transactions_request(
 
 def serialize_acs_request(
     f: "ContractFilter", ledger_id: str, party: Party
-) -> "acs_pb2.GetActiveContractsRequest":
-    return acs_pb2.GetActiveContractsRequest(
+) -> "lapipb.GetActiveContractsRequest":
+    return lapipb.GetActiveContractsRequest(
         ledger_id=ledger_id, filter=serialize_transaction_filter(f, party)
     )
 
 
 def serialize_event_id_request(
     ledger_id: str, event_id: str, requesting_parties: "Sequence[Party]"
-) -> "txs_pb2.GetTransactionByEventIdRequest":
-    return txs_pb2.GetTransactionByEventIdRequest(
+) -> "lapipb.GetTransactionByEventIdRequest":
+    return lapipb.GetTransactionByEventIdRequest(
         ledger_id=ledger_id, event_id=event_id, requesting_parties=requesting_parties
     )
 
 
 def serialize_transaction_filter(
     contract_filter: "ContractFilter", party: Party
-) -> "txf_pb2.TransactionFilter":
+) -> "lapipb.TransactionFilter":
     identifiers = (
         [Codec.encode_identifier(tt) for tt in contract_filter.templates]
         if contract_filter.templates is not None
@@ -297,22 +289,22 @@ def serialize_transaction_filter(
     if contract_filter.party_groups is not None:
         parties.extend(contract_filter.party_groups)
 
-    filters_by_party = {}  # type: Dict[str, txf_pb2.Filters]
+    filters_by_party = {}  # type: Dict[str, lapipb.Filters]
     for party in parties:
         if identifiers is not None:
-            filters_by_party[party] = txf_pb2.Filters(
-                inclusive=txf_pb2.InclusiveFilters(template_ids=identifiers)
+            filters_by_party[party] = lapipb.Filters(
+                inclusive=lapipb.InclusiveFilters(template_ids=identifiers)
             )
         else:
-            filters_by_party[party] = txf_pb2.Filters()
+            filters_by_party[party] = lapipb.Filters()
 
-    return txf_pb2.TransactionFilter(filters_by_party=filters_by_party)
+    return lapipb.TransactionFilter(filters_by_party=filters_by_party)
 
 
 def to_transaction_events(
     context: "BaseEventDeserializationContext",
-    tx_stream_pb: "Iterable[txs_pb2.GetTransactionsResponse]",
-    tt_stream_pb: "Optional[Iterable[txs_pb2.GetTransactionTreesResponse]]",
+    tx_stream_pb: "Iterable[lapipb.GetTransactionsResponse]",
+    tt_stream_pb: "Optional[Iterable[lapipb.GetTransactionTreesResponse]]",
     last_offset_override: "Optional[str]",
 ) -> "Sequence[BaseEvent]":
     """
@@ -371,7 +363,7 @@ def to_acs_events(
 
 
 def from_transaction_tree(
-    context: "BaseEventDeserializationContext", tt_pb: "tx_pb2.TransactionTree"
+    context: "BaseEventDeserializationContext", tt_pb: "lapipb.TransactionTree"
 ) -> "Sequence[OffsetEvent]":
     t_context = context.transaction(
         time=to_datetime(tt_pb.effective_at),
@@ -390,7 +382,7 @@ def from_transaction_tree(
 
 
 def to_acs_event(
-    context: "BaseEventDeserializationContext", acs_pb: "acs_pb2.GetActiveContractsResponse"
+    context: "BaseEventDeserializationContext", acs_pb: "lapipb.GetActiveContractsResponse"
 ):
     acs_context = context.active_contract_set(acs_pb.offset, acs_pb.workflow_id)
     contract_events = [
@@ -402,7 +394,7 @@ def to_acs_event(
 
 
 def to_transaction_chunk(
-    context: "BaseEventDeserializationContext", tx_pb: "tx_pb2.Transaction"
+    context: "BaseEventDeserializationContext", tx_pb: "lapipb.Transaction"
 ) -> "Sequence[OffsetEvent]":
     """
     Return a sequence of events parsed from a Ledger API ``Transaction`` protobuf message.
@@ -438,7 +430,7 @@ def to_transaction_chunk(
 
 def to_event(
     context: "Union[TransactionEventDeserializationContext, ActiveContractSetEventDeserializationContext]",
-    evt_pb: "Union[event_pb2.Event, tx_pb2.TreeEvent]",
+    evt_pb: "Union[lapipb.Event, lapipb.TreeEvent]",
 ) -> "Optional[OffsetEvent]":
     try:
         event_type = evt_pb.WhichOneof("event")
@@ -454,12 +446,12 @@ def to_event(
     elif "exercised" == event_type:
         return to_exercised_event(
             cast(TransactionEventDeserializationContext, context),
-            cast(tx_pb2.TreeEvent, evt_pb).exercised,
+            cast(lapipb.TreeEvent, evt_pb).exercised,
         )
     elif "archived" == event_type:
         return to_archived_event(
             cast(TransactionEventDeserializationContext, context),
-            cast(event_pb2.Event, evt_pb).archived,
+            cast(lapipb.Event, evt_pb).archived,
         )
     else:
         raise ValueError(f"unknown event type: {event_type}")
@@ -467,7 +459,7 @@ def to_event(
 
 def to_created_event(
     context: "Union[TransactionEventDeserializationContext, ActiveContractSetEventDeserializationContext]",
-    cr: "event_pb2.CreatedEvent",
+    cr: "lapipb.CreatedEvent",
 ) -> "Optional[ContractCreateEvent]":
     tt = con(Codec.decode_identifier(cr.template_id))
 
@@ -481,7 +473,7 @@ def to_created_event(
 
 
 def to_exercised_event(
-    context: "TransactionEventDeserializationContext", er: "event_pb2.ExercisedEvent"
+    context: "TransactionEventDeserializationContext", er: "lapipb.ExercisedEvent"
 ) -> "Optional[ContractExercisedEvent]":
     name = Codec.decode_identifier(er.template_id)
     tt = con(name)
@@ -516,7 +508,7 @@ def to_exercised_event(
 
 
 def to_archived_event(
-    context: "TransactionEventDeserializationContext", ar: "event_pb2.ArchivedEvent"
+    context: "TransactionEventDeserializationContext", ar: "lapipb.ArchivedEvent"
 ) -> "Optional[ContractArchiveEvent]":
     tt = con(Codec.decode_identifier(ar.template_id))
     event_id = ar.event_id
@@ -527,6 +519,6 @@ def to_archived_event(
     return context.contract_archived_event(cid, None, event_id, witness_parties)
 
 
-def to_type_con_name(identifier: "value_pb2.Identifier") -> "TypeConName":
+def to_type_con_name(identifier: "lapipb.Identifier") -> "TypeConName":
     warnings.warn("Use Codec.decode_identifier instead.", DeprecationWarning, stacklevel=2)
     return Codec.decode_identifier(identifier)
diff --git a/python/dazl/protocols/v1/pb_parse_metadata.py b/python/dazl/protocols/v1/pb_parse_metadata.py
index b3c06b34..1772718e 100644
--- a/python/dazl/protocols/v1/pb_parse_metadata.py
+++ b/python/dazl/protocols/v1/pb_parse_metadata.py
@@ -20,7 +20,7 @@
 from toposort import toposort_flatten
 
 from ... import LOG
-from ..._gen.com.daml.daml_lf_1_14.daml_lf_pb2 import ArchivePayload as G_ArchivePayload
+from ..._gen.com.daml.daml_lf_1_14 import daml_lf_pb2 as lfpb
 from ...damlast.daml_lf_1 import (
     Archive,
     DefDataType,
@@ -71,13 +71,13 @@ def parse_archive_payload(raw_bytes: bytes, package_id: "Optional[PackageRef]" =
 
 @dataclass(frozen=True)
 class ArchiveDependencyResult:
-    sorted_archives: "Mapping[PackageRef, G_ArchivePayload]"
-    unresolvable_archives: "Mapping[PackageRef, G_ArchivePayload]"
+    sorted_archives: "Mapping[PackageRef, lfpb.ArchivePayload]"
+    unresolvable_archives: "Mapping[PackageRef, lfpb.ArchivePayload]"
 
 
 # noinspection PyDeprecation
 def find_dependencies(
-    metadatas_pb: "Mapping[PackageRef, G_ArchivePayload]",
+    metadatas_pb: "Mapping[PackageRef, lfpb.ArchivePayload]",
     existing_package_ids: "Collection[PackageRef]",
 ) -> "ArchiveDependencyResult":
     """
diff --git a/python/dazl/protocols/v1/pb_ser_command.py b/python/dazl/protocols/v1/pb_ser_command.py
index 68ea1030..9a4adcf1 100644
--- a/python/dazl/protocols/v1/pb_ser_command.py
+++ b/python/dazl/protocols/v1/pb_ser_command.py
@@ -7,18 +7,7 @@
 from typing import TYPE_CHECKING, Any, Union
 import warnings
 
-from ..._gen.com.daml.ledger.api.v1.command_service_pb2 import (
-    SubmitAndWaitRequest as G_SubmitAndWaitRequest,
-)
-from ..._gen.com.daml.ledger.api.v1.commands_pb2 import (
-    Command as G_Command,
-    Commands as G_Commands,
-    CreateAndExerciseCommand as G_CreateAndExerciseCommand,
-    CreateCommand as G_CreateCommand,
-    ExerciseByKeyCommand as G_ExerciseByKeyCommand,
-    ExerciseCommand as G_ExerciseCommand,
-)
-from ..._gen.com.daml.ledger.api.v1.value_pb2 import Identifier as G_Identifier
+from ..._gen.com.daml.ledger.api import v1 as lapipb
 from ...damlast.daml_lf_1 import TypeConName
 from ...damlast.util import module_local_name, module_name, package_ref
 from ...ledger.grpc.codec_aio import Codec
@@ -31,8 +20,10 @@
     from ...model.types import TypeReference
     from ...model.writing import CommandPayload
 
+__all__ = ["as_identifier", "ProtobufSerializer"]
 
-def as_identifier(tref: "Union[TypeReference, TypeConName]") -> "G_Identifier":
+
+def as_identifier(tref: "Union[TypeReference, TypeConName]") -> "lapipb.Identifier":
     from ...model.types import TypeReference
 
     warnings.warn("Use Codec.encode_identifier instead.", DeprecationWarning, stacklevel=2)
@@ -53,10 +44,10 @@ class ProtobufSerializer(AbstractSerializer):
 
     def serialize_command_request(
         self, command_payload: "CommandPayload"
-    ) -> G_SubmitAndWaitRequest:
+    ) -> "lapipb.SubmitAndWaitRequest":
         commands = [self.serialize_command(command) for command in command_payload.commands]
-        return G_SubmitAndWaitRequest(
-            commands=G_Commands(
+        return lapipb.SubmitAndWaitRequest(
+            commands=lapipb.Commands(
                 ledger_id=command_payload.ledger_id,
                 workflow_id=command_payload.workflow_id,
                 application_id=command_payload.application_id,
@@ -71,28 +62,30 @@ def serialize_command_request(
             )
         )
 
-    def serialize_create_command(self, name: "TypeConName", template_args: "Any") -> G_Command:
+    def serialize_create_command(
+        self, name: "TypeConName", template_args: "Any"
+    ) -> "lapipb.Command":
         create_ctor, create_value = template_args
         if create_ctor != "record":
             raise ValueError("Template values must resemble records")
 
-        cmd = G_CreateCommand()
+        cmd = lapipb.CreateCommand()
         _set_template(cmd.template_id, name)
         cmd.create_arguments.MergeFrom(create_value)
-        return G_Command(create=cmd)
+        return lapipb.Command(create=cmd)
 
     def serialize_exercise_command(
         self, contract_id: "ContractId", choice_name: str, choice_args: "Any"
-    ) -> G_Command:
+    ) -> lapipb.Command:
         type_ref = contract_id.value_type
         ctor, value = choice_args
 
-        cmd = G_ExerciseCommand()
+        cmd = lapipb.ExerciseCommand()
         _set_template(cmd.template_id, type_ref)
         cmd.contract_id = contract_id.value
         cmd.choice = choice_name
         set_value(cmd.choice_argument, ctor, value)
-        return G_Command(exercise=cmd)
+        return lapipb.Command(exercise=cmd)
 
     def serialize_exercise_by_key_command(
         self,
@@ -100,16 +93,16 @@ def serialize_exercise_by_key_command(
         key_arguments: Any,
         choice_name: str,
         choice_arguments: Any,
-    ) -> G_Command:
+    ) -> lapipb.Command:
         key_ctor, key_value = key_arguments
         choice_ctor, choice_value = choice_arguments
 
-        cmd = G_ExerciseByKeyCommand()
+        cmd = lapipb.ExerciseByKeyCommand()
         _set_template(cmd.template_id, template_name)
         set_value(cmd.contract_key, key_ctor, key_value)
         cmd.choice = choice_name
         set_value(cmd.choice_argument, choice_ctor, choice_value)
-        return G_Command(exerciseByKey=cmd)
+        return lapipb.Command(exerciseByKey=cmd)
 
     def serialize_create_and_exercise_command(
         self,
@@ -117,21 +110,21 @@ def serialize_create_and_exercise_command(
         create_arguments: "Any",
         choice_name: str,
         choice_arguments: Any,
-    ) -> G_Command:
+    ) -> lapipb.Command:
         create_ctor, create_value = create_arguments
         if create_ctor != "record":
             raise ValueError("Template values must resemble records")
         choice_ctor, choice_value = choice_arguments
 
-        cmd = G_CreateAndExerciseCommand()
+        cmd = lapipb.CreateAndExerciseCommand()
         _set_template(cmd.template_id, template_name)
         cmd.create_arguments.MergeFrom(create_value)
         cmd.choice = choice_name
         set_value(cmd.choice_argument, choice_ctor, choice_value)
-        return G_Command(createAndExercise=cmd)
+        return lapipb.Command(createAndExercise=cmd)
 
 
-def _set_template(message: G_Identifier, name: "TypeConName") -> None:
+def _set_template(message: "lapipb.Identifier", name: "TypeConName") -> None:
     message.package_id = package_ref(name)
     message.module_name = str(module_name(name))
     message.entity_name = module_local_name(name)
diff --git a/python/dazl/values/protobuf.py b/python/dazl/values/protobuf.py
index cb669d88..8604f3f7 100644
--- a/python/dazl/values/protobuf.py
+++ b/python/dazl/values/protobuf.py
@@ -6,7 +6,7 @@
 from google.protobuf import timestamp_pb2
 from google.protobuf.empty_pb2 import Empty
 
-from .._gen.com.daml.ledger.api.v1 import value_pb2
+from .._gen.com.daml.ledger.api import v1 as lapipb
 from ..damlast.daml_lf_1 import DefDataType, Type
 from ..damlast.util import find_variant_type
 from ..prim import (
@@ -44,7 +44,7 @@ class ProtobufDecoder(ValueMapper):
     def data_record(
         self, context: "Context", dt: "DefDataType", record: "DefDataType.Fields", obj: "Any"
     ) -> "Any":
-        msg = get_value(obj, "record", value_pb2.Record)
+        msg = get_value(obj, "record", lapipb.Record)
 
         d = dict()
         for fld_metadata, fld_data in zip(record.fields, msg.fields):
@@ -57,7 +57,7 @@ def data_record(
     def data_variant(
         self, context: "Context", dt: "DefDataType", variant: "DefDataType.Fields", obj: "Any"
     ) -> "Any":
-        msg = get_value(obj, "variant", value_pb2.Variant)
+        msg = get_value(obj, "variant", lapipb.Variant)
         obj_ctor = msg.constructor
         obj_value = msg.value
         obj_type = find_variant_type(dt, variant, obj_ctor)
@@ -73,7 +73,7 @@ def data_enum(
         enum: "DefDataType.EnumConstructors",
         obj: "Any",
     ) -> "Any":
-        msg = get_value(obj, "enum", value_pb2.Enum)
+        msg = get_value(obj, "enum", lapipb.Enum)
         return context.value_validate_enum(msg.constructor, enum)
 
     def prim_unit(self, context: "Context", obj: "Any") -> "Any":
@@ -95,7 +95,7 @@ def prim_party(self, context: "Context", obj: "Any") -> "Any":
         return to_party(get_value(obj, "party", str))
 
     def prim_list(self, context: "Context", item_type: "Type", obj: "Any") -> "Any":
-        msg = get_value(obj, "list", value_pb2.List)
+        msg = get_value(obj, "list", lapipb.List)
         return context.convert_list(item_type, msg.elements)
 
     def prim_date(self, context: "Context", obj: "Any") -> "Any":
@@ -107,12 +107,12 @@ def prim_contract_id(self, context: "Context", item_type: "Type", obj: "Any") ->
         return context.convert_contract_id(item_type, msg)
 
     def prim_optional(self, context: "Context", t: "Type", obj: "Any") -> "Any":
-        msg = get_value(obj, "optional", value_pb2.Optional)
+        msg = get_value(obj, "optional", lapipb.Optional)
         maybe_val = msg.value if msg.HasField("value") else None
         return context.convert_optional(t, maybe_val)
 
     def prim_text_map(self, context: "Context", item_type: "Type", obj: "Any") -> "Any":
-        msg = get_value(obj, "map", value_pb2.Map)
+        msg = get_value(obj, "map", lapipb.Map)
         mapping = {entry_pb.key: entry_pb.value for entry_pb in msg.entries}
         return context.convert_text_map(item_type, mapping)
 
@@ -123,7 +123,7 @@ def prim_numeric(self, context: "Context", nat: int, obj: "Any") -> "Any":
     def prim_gen_map(
         self, context: "Context", key_type: "Type", value_type: "Type", obj: "Any"
     ) -> "Any":
-        msg = get_value(obj, "gen_map", value_pb2.GenMap)
+        msg = get_value(obj, "gen_map", lapipb.GenMap)
 
         obj = {}
         for i, entry in enumerate(msg.entries):
@@ -138,7 +138,7 @@ class ProtobufEncoder(ValueMapper):
     def data_record(
         self, context: "Context", dt: "DefDataType", record: "DefDataType.Fields", obj: "Any"
     ) -> "Any":
-        msg = value_pb2.Record()
+        msg = lapipb.Record()
 
         for fld in record.fields:
             entry = msg.fields.add()
@@ -156,7 +156,7 @@ def data_variant(
 
         msg_case, msg_value = context.append_path(obj_ctor).convert(obj_type, obj_value)
 
-        msg = value_pb2.Variant()
+        msg = lapipb.Variant()
         msg.constructor = obj_ctor
         set_value(msg.value, msg_case, msg_value)
 
@@ -169,7 +169,7 @@ def data_enum(
         enum: "DefDataType.EnumConstructors",
         obj: "Any",
     ) -> "Any":
-        msg = value_pb2.Enum()
+        msg = lapipb.Enum()
         msg.constructor = context.value_validate_enum(obj, enum)
         return "enum", msg
 
@@ -192,7 +192,7 @@ def prim_party(self, context: "Context", obj: "Any") -> "Any":
         return "party", to_str(obj)
 
     def prim_list(self, context: "Context", item_type: "Type", obj: "Any") -> "Any":
-        msg = value_pb2.List()
+        msg = lapipb.List()
         for i, item in enumerate(obj):
             value = msg.elements.add()
             ctor, val = context.append_path(f"[{i}").convert(item_type, item)
@@ -206,14 +206,14 @@ def prim_contract_id(self, context: "Context", item_type: "Type", obj: "Any") ->
         return "contract_id", to_str(obj)
 
     def prim_optional(self, context: "Context", item_type: "Type", obj: "Any") -> "Any":
-        msg = value_pb2.Optional()
+        msg = lapipb.Optional()
         if obj is not None:
             ctor, val = context.append_path("?").convert(item_type, obj)
             set_value(msg.value, ctor, val)
         return "optional", msg
 
     def prim_text_map(self, context: "Context", item_type: "Type", obj: "Any") -> "Any":
-        msg = value_pb2.Map()
+        msg = lapipb.Map()
         for key, value in obj.items():
             entry = msg.entries.add()
             entry.key = key
@@ -228,7 +228,7 @@ def prim_numeric(self, context: "Context", nat: int, obj: "Any") -> "Any":
     def prim_gen_map(
         self, context: "Context", key_type: "Type", value_type: "Type", obj: "Any"
     ) -> "Any":
-        msg = value_pb2.GenMap()
+        msg = lapipb.GenMap()
         for i, (key, value) in enumerate(obj.items()):
             entry = msg.entries.add()
             key_ctor, key_val = context.append_path(f"[key: {i}]").convert(key_type, key)
@@ -242,7 +242,7 @@ def get_value(obj: "Any", field: str, pb_type: "PyType[T]") -> "T":
     return obj if isinstance(obj, pb_type) else getattr(obj, field)
 
 
-def set_value(message: "value_pb2.Value", ctor: "Optional[str]", value: "Any") -> None:
+def set_value(message: "lapipb.Value", ctor: "Optional[str]", value: "Any") -> None:
     """
     Work around the somewhat crazy API of Python's gRPC library to apply a known value to a
     :class:`Value`.


Test patch:
diff --git a/python/tests/unit/test_pb_serialize.py b/python/tests/unit/test_pb_serialize.py
index 02d405d0..6f9439f6 100644
--- a/python/tests/unit/test_pb_serialize.py
+++ b/python/tests/unit/test_pb_serialize.py
@@ -4,8 +4,8 @@
 from dataclasses import dataclass
 from typing import Generator
 
-from dazl._gen.com.daml.ledger.api.v1.commands_pb2 import Command as G_Command
-from dazl._gen.com.daml.ledger.api.v1.value_pb2 import (
+from dazl._gen.com.daml.ledger.api.v1 import (
+    Command as G_Command,
     RecordField as G_RecordField,
     Value as G_Value,
 )
diff --git a/python/tests/unit/test_values_protobuf.py b/python/tests/unit/test_values_protobuf.py
index 8775b8ce..a2cc03f2 100644
--- a/python/tests/unit/test_values_protobuf.py
+++ b/python/tests/unit/test_values_protobuf.py
@@ -3,7 +3,7 @@
 
 from datetime import date, datetime, timedelta, timezone
 
-from dazl._gen.com.daml.ledger.api.v1 import value_pb2
+from dazl._gen.com.daml.ledger.api import v1 as lapipb
 from dazl.damlast import CachedDarFile, daml_types as daml
 from dazl.damlast.lookup import MultiPackageLookup
 from dazl.values import Context, ProtobufDecoder, ProtobufEncoder
@@ -42,7 +42,7 @@ def test_values_protobuf_encode_bool_false(encode_context):
 def test_values_protobuf_encode_enum(encode_context, lookup):
     color_enum_type = daml.con(lookup.data_type_name("*:AllKindsOf:Color"))
     actual = encode_context.convert(color_enum_type, "Red")
-    assert actual == ("enum", value_pb2.Enum(constructor="Red"))
+    assert actual == ("enum", lapipb.Enum(constructor="Red"))
 
 
 def test_values_protobuf_encode_enum_invalid(encode_context, lookup):
@@ -80,7 +80,7 @@ def test_values_protobuf_encode_datetime(encode_context):
 
 
 def test_values_protobuf_decode_date(decode_context):
-    value = value_pb2.Value()
+    value = lapipb.Value()
     value.date = 18262
 
     actual = decode_context.convert(daml.Date, value)
@@ -88,7 +88,7 @@ def test_values_protobuf_decode_date(decode_context):
 
 
 def test_values_protobuf_decode_date_far_in_the_past(decode_context):
-    value = value_pb2.Value()
+    value = lapipb.Value()
     value.date = -1
 
     actual = decode_context.convert(daml.Date, value)
@@ -96,7 +96,7 @@ def test_values_protobuf_decode_date_far_in_the_past(decode_context):
 
 
 def test_values_protobuf_decode_datetime(decode_context):
-    value = value_pb2.Value()
+    value = lapipb.Value()
     value.timestamp = ARBITRARY_DATETIME_TIMESTAMP
 
     actual = decode_context.convert(daml.Time, value)