Notice: Over the next few months, we're reorganizing the App Engine documentation site to make it easier to find content and better align with the rest of Google Cloud products. The same content will be available, but the navigation will now match the rest of the Cloud products. If you have feedback or questions as you navigate the site, click Send Feedback.

Python 2 is no longer supported by the community. We recommend that you migrate Python 2 apps to Python 3.

The Service Class

Stay organized with collections Save and categorize content based on your preferences.

Google Protocol RPC services are constructed either via a constructor or a factory which takes no parameters. However, some applications need to pass some state or configuration into a service across multiple requests. To do this, define parameters to the constructor of the service and use the new_factory() class method to build a factory that will transmit parameters to the constructor. For example:

from protorpc import remote

class MyService(remote.Service):

    def __init__(self, configuration, state):
        self.configuration = configuration
        self.state = state

configuration = MyServiceConfiguration()
global_state = MyServiceState()

my_service_factory = MyService.new_factory(configuration,

The contract with any service handler is that a new service object is created to handle each user request, and that the construction does not take any parameters. The factory satisfies this condition:

new_instance = my_service_factory()
assert new_instance.state is global_state

Service is provided by the protorpc.remote module.

Class Properties

Services instances one property:

Request state associated with this Service instance.

Class Methods

The Service class provides the following class methods:


Gets all remote methods for a Service class.

Note: Built-in methods do not appear in the dictionary of remote methods.

Returns a dictionary that maps method names to remote methods.

new_factory(args, **kwargs)

Creates a factory for a service. Useful for passing configuration or state objects to the service. Accepts arbitrary parameters and keywords, however, underlying service must accept also accept not other parameters in its constructor.

Arguments to pass to the service constructor.

Returns a factory function that creates a new instance and forwards arguments and keywords to the constructor.

Instance Methods

Service instances have the following methods:

A RequestState instance.