nautilus.services package

Submodules

nautilus.services.apiGateway module

class nautilus.services.apiGateway.APIGateway(*args, **kwds)[source]

Bases: nautilus.services.service.Service

This provides a single endpoint that other services and clients can use to query the cloud without worrying about the distributed nature of the system.

Example

# external imports
import nautilus

# local imports
from .schema import schema

class MyAPIGateway(nautilus.APIGateway):
    schema = schema
action_handler

alias of APIActionHandler

announce()[source]
api_request_handler_class

alias of APIQueryHandler

auth_criteria

This attribute provides the mapping of services to their auth requirement

Returns:the mapping from services to their auth requirements.
Return type:(dict)
connection_resolver(connection_name, object)[source]
get_models()[source]

Returns the models managed by this service.

Returns:the models managed by the service
Return type:(list)
init_db()[source]

This function configures the database used for models to make the configuration parameters.

init_routes()[source]
login_user(password, **kwds)[source]

This function handles the registration of the given user credentials in the database

model

alias of UserPassword

mutation_resolver(mutation_name, args, fields)[source]

the default behavior for mutations is to look up the event, publish the correct event type with the args as the body, and return the fields contained in the result

name = 'api'
object_resolver(object_name, fields, obey_auth=False, current_user=None, **filters)[source]

This function resolves a given object in the remote backend services

register_user(password, **kwds)[source]

This function is used to provide a sessionToken for later requests.

Parameters:uid (str) – The
secret_key = None
user_session(user)[source]

This method handles what information the api gateway stores about a particular user in their session.

nautilus.services.authService module

nautilus.services.connectionService module

class nautilus.services.connectionService.ConnectionService(**kwargs)[source]

Bases: nautilus.services.modelService.ModelService

This service manages a “one-way” connection between two services. The underlying schema and database are automatically generated to match the primary keys of the linked services.

This service will listen for actions indicating the deletion of a related model and remove any related fields to maintain consistency. And provides a way for the api gateway to deduce the relationship between services when summarizing the cloud.

Parameters:services (list of nautilus.Service) – The list of services to connect.

Example

# external imports
import nautilus

class ServiceConfig:
    database_url = 'sqlite:////tmp/connections.db'

class MyConnection(nautilus.ConnectionService):
    config = ServiceConfig

    from_service = ('service_one',)
    to_service = ('service_one',)
action_handler
from_service = None
name = 'connectionService'
summarize(**extra_fields)[source]
to_service = None

nautilus.services.modelService module

class nautilus.services.modelService.ModelService(model=None, **kwargs)[source]

Bases: nautilus.services.service.Service

This service acts as the primary data store in your cloud. It manages the records of a single model by listening for actions that indicate a record mutation as well as emitting actions when the mutations have finished (whether successfully or not). The external API is automatically generated to match the given model.

Parameters:model (nautilus.BaseModel) – The nautilus model to manage.

Example

import nautilus
import nautilus.models as models

class Model(models.BaseModel):
    name = models.fields.CharField()

class ServiceConfig:
    database_url = 'sqlite:////tmp/models.db'

class MyModelService(nautilus.ModelService):
    model = Model
    config = ServiceConfig
action_handler
get_models()[source]

Returns the models managed by this service.

Returns:the models managed by the service
Return type:(list)
init_db()[source]

This function configures the database used for models to make the configuration parameters.

model = None
name = 'modelService'
summarize(**extra_fields)[source]

nautilus.services.service module

class nautilus.services.service.Service(name=None, schema=None, action_handler=None, config=None, auth=True)[source]

Bases: object

This is the base class for all services that are part of a nautilus cloud. This class provides basic functionalities such as registration, responding to actions, and predictable api endpoints.

Parameters:
  • action_handler (optional, function) – The callback function fired when an action is recieved. If None, the service does not connect to the action queue.
  • config (optional, class) – A python class to use for configuring the service.
  • name (string) – The name of the service. This will be used to register the service with the registry as act as the designator for a ServiceObjectType.
  • schema (optional, graphql.core.type.GraphQLSchema) – The GraphQL schema which acts as a basis for the external API. If None, no endpoints are added to the service.

Example

import nautilus
from nautilus.api.util import create_model_schema
from nautilus.network import crud_handler
import nautilus.models as models

class Model(models.BaseModel):
    name = models.fields.CharField()

class MyService(nautilus.Service):
    name = 'My Awesome Service'
    schema = create_model_schema(Model)
    action_handler = crud_handler(Model)
action_handler

alias of ServiceActionHandler

add_http_endpoint(url, request_handler)[source]

This method provides a programatic way of added invidual routes to the http server.

Parameters:
  • url (str) – the url to be handled by the request_handler
  • request_handler (nautilus.network.RequestHandler) – The request handler
announce()[source]

This method is used to announce the existence of the service

api_request_handler_class

alias of GraphQLRequestHandler

cleanup()[source]

This function is called when the service has finished running regardless of intentionally or not.

config = None
init_action_handler()[source]
init_app()[source]
init_routes()[source]
name = 'service'
classmethod route(route, config=None)[source]

This method provides a decorator for adding endpoints to the http server.

Parameters:
  • route (str) – The url to be handled by the RequestHandled
  • config (dict) – Configuration for the request handler

Example

import nautilus
from nauilus.network.http import RequestHandler

class MyService(nautilus.Service):
    # ...

@MyService.route('/')
class HelloWorld(RequestHandler):
    def get(self):
        return self.finish('hello world')
run(host='localhost', port=8000, shutdown_timeout=60.0, **kwargs)[source]

This function starts the service’s network intefaces.

Parameters:port (int) – The port for the http server.
schema = None
summarize(**extra_fields)[source]
class nautilus.services.service.ServiceActionHandler[source]

Bases: nautilus.network.events.consumers.actions.ActionHandler

handle_action(action_type, payload, **kwds)[source]

The default action Handler has no action.

class nautilus.services.service.ServiceMetaClass(name, bases, attributes)[source]

Bases: type

nautilus.services.serviceManager module

This module defines a small singleton that runs various scripts in the context of the service.

class nautilus.services.serviceManager.ServiceManager(service, config=None)[source]

Bases: object

run()[source]

run the command manager

Module contents