def configure_remote_put(remote_url, target_app_id, extra_headers=None):
  if not target_app_id or not remote_url:
    raise ConfigurationError('app_id and remote_url required')

  for stub_class in (RemoteApiDatastoreV3Stub, RemoteApiDatastoreV4Stub):
    service_name = stub_class.ServiceName()
    original_datastore_stub = apiproxy_stub_map.apiproxy.GetStub(service_name)
    if isinstance(original_datastore_stub, stub_class):
      logging.info('Datastore Admin %s RemoteApi stub is already configured.',
                   service_name)
      if not StubConfigEqualsRequestedConfig(
          original_datastore_stub, remote_url, target_app_id, extra_headers):
        logging.warning('Requested Datastore Admin %s RemoteApi stub '
                        'configuration differs from existing configuration, '
                        'attempting reconfiguration.', service_name)
        datastore_stub = stub_class(remote_url, target_app_id, extra_headers,
                                    original_datastore_stub.normal_stub)
        apiproxy_stub_map.apiproxy.ReplaceStub(service_name, datastore_stub)
    else:
      datastore_stub = stub_class(remote_url, target_app_id, extra_headers,
                                  original_datastore_stub)
      apiproxy_stub_map.apiproxy.RegisterStub(service_name, datastore_stub)
Does necessary setup to intercept v3 Put and v4 AllocateIds.
dataset/ETHPy150Open GoogleCloudPlatform/python-compat-runtime/appengine-compat/exported_appengine_sdk/google/appengine/ext/datastore_admin/remote_api_put_stub.py/configure_remote_put