boto3.resources.model

The models defined in this file represent the resource JSON description format and provide a layer of abstraction from the raw JSON. The advantages of this are:

  • Pythonic interface (e.g. action.request.operation)
  • Consumers need not change for minor JSON changes (e.g. renamed field)

These models are used both by the resource factory to generate resource classes as well as by the documentation generator.

Module Contents

logger
class Identifier(name, member_name=None)

Bases:object

A resource identifier, given by its name.

Parameters:name (string) – The name of the identifier
class Action(name, definition, resource_defs)

Bases:object

A service operation action.

Parameters:
  • name (string) – The name of the action
  • definition (dict) – The JSON definition
  • resource_defs (dict) – All resources defined in the service
class DefinitionWithParams(definition)

Bases:object

An item which has parameters exposed via the params property. A request has an operation and parameters, while a waiter has a name, a low-level waiter name and parameters.

Parameters:definition (dict) – The JSON definition
params

Get a list of auto-filled parameters for this request.

Type:list(Parameter)
class Parameter(target, source, name=None, path=None, value=None, **kwargs)

Bases:object

An auto-filled parameter which has a source and target. For example, the QueueUrl may be auto-filled from a resource’s url identifier when making calls to queue.receive_messages.

Parameters:
  • target (string) – The destination parameter name, e.g. QueueUrl
  • source_type (string) – Where the source is defined.
  • source (string) – The source name, e.g. Url
class Request(definition)

Bases:boto3.resources.model.DefinitionWithParams

A service operation action request.

Parameters:definition (dict) – The JSON definition
class Waiter(name, definition)

Bases:boto3.resources.model.DefinitionWithParams

An event waiter specification.

Parameters:
  • name (string) – Name of the waiter
  • definition (dict) – The JSON definition
PREFIX = WaitUntil
class ResponseResource(definition, resource_defs)

Bases:object

A resource response to create after performing an action.

Parameters:
  • definition (dict) – The JSON definition
  • resource_defs (dict) – All resources defined in the service
identifiers

A list of resource identifiers.

Type:list(Identifier)
model

Get the resource model for the response resource.

Type:ResourceModel
class Collection

Bases:boto3.resources.model.Action

A group of resources. See Action.

Parameters:
  • name (string) – The name of the collection
  • definition (dict) – The JSON definition
  • resource_defs (dict) – All resources defined in the service
batch_actions

Get a list of batch actions supported by the resource type contained in this action. This is a shortcut for accessing the same information through the resource model.

Return type:list(Action)
class ResourceModel(name, definition, resource_defs)

Bases:object

A model representing a resource, defined via a JSON description format. A resource has identifiers, attributes, actions, sub-resources, references and collections. For more information on resources, see guide_resources.

Parameters:
  • name (string) – The name of this resource, e.g. sqs or Queue
  • definition (dict) – The JSON definition
  • resource_defs (dict) – All resources defined in the service
identifiers

Get a list of resource identifiers.

Type:list(Identifier)
load

Get the load action for this resource, if it is defined.

Type:Action or None
actions

Get a list of actions for this resource.

Type:list(Action)
batch_actions

Get a list of batch actions for this resource.

Type:list(Action)
subresources

Get a list of sub-resources.

Type:list(ResponseResource)
references

Get a list of reference resources.

Type:list(ResponseResource)
collections

Get a list of collections for this resource.

Type:list(Collection)
waiters

Get a list of waiters for this resource.

Type:list(Waiter)
load_rename_map(self, shape=None)

Load a name translation map given a shape. This will set up renamed values for any collisions, e.g. if the shape, an action, and a subresource all are all named foo then the resource will have an action foo, a subresource named Foo and a property named foo_attribute. This is the order of precedence, from most important to least important:

  • Load action (resource.load)
  • Identifiers
  • Actions
  • Subresources
  • References
  • Collections
  • Waiters
  • Attributes (shape members)

Batch actions are only exposed on collections, so do not get modified here. Subresources use upper camel casing, so are unlikely to collide with anything but other subresources.

Creates a structure like this:

renames = {
    ('action', 'id'): 'id_action',
    ('collection', 'id'): 'id_collection',
    ('attribute', 'id'): 'id_attribute'
}

# Get the final name for an action named 'id'
name = renames.get(('action', 'id'), 'id')
Parameters:shape (botocore.model.Shape) – The underlying shape for this resource.
_load_name_with_category(self, names, name, category, snake_case=True)

Load a name with a given category, possibly renaming it if that name is already in use. The name will be stored in names and possibly be set up in self._renamed.

Parameters:
  • names (set) – Existing names (Python attributes, properties, or methods) on the resource.
  • name (string) – The original name of the value.
  • category (string) – The value type, such as ‘identifier’ or ‘action’
  • snake_case (bool) – True (default) if the name should be snake cased.
_get_name(self, category, name, snake_case=True)

Get a possibly renamed value given a category and name. This uses the rename map set up in load_rename_map, so that method must be called once first.

Parameters:
  • category (string) – The value type, such as ‘identifier’ or ‘action’
  • name (string) – The original name of the value
  • snake_case (bool) – True (default) if the name should be snake cased.
Return type:

string

Returns:

Either the renamed value if it is set, otherwise the original name.

get_attributes(self, shape)

Get a dictionary of attribute names to original name and shape models that represent the attributes of this resource. Looks like the following:

{
‘some_name’: (‘SomeName’, <Shape…>)

}

Parameters:shape (botocore.model.Shape) – The underlying shape for this resource.
Return type:dict
Returns:Mapping of resource attributes.
_get_has_definition(self)

Get a has relationship definition from a model, where the service resource model is treated special in that it contains a relationship to every resource defined for the service. This allows things like s3.Object('bucket-name', 'key') to work even though the JSON doesn’t define it explicitly.

Return type:dict
Returns:Mapping of names to subresource and reference definitions.

Get a list of sub-resources or references.

Parameters:subresources (bool) – True to get sub-resources, False to get references.
Return type:list(ResponseResource)