boto3.resources.collection.
CollectionFactory
[source]¶A factory to create new
CollectionManager
and ResourceCollection
subclasses from a Collection
model. These subclasses include methods to perform batch operations.
load_from_definition
(resource_name, collection_model, service_context, event_emitter)[source]¶Loads a collection from a model, creating a new
CollectionManager
subclass
with the correct properties and methods, named based on the service
and resource name, e.g. ec2.InstanceCollectionManager. It also
creates a new ResourceCollection
subclass which is used
by the new manager class.
service_name
.ServiceContext
) -- Context about the AWS serviceHierarchialEmitter
) -- An event emitterSubclass of CollectionManager
The collection class.
boto3.resources.collection.
CollectionManager
(collection_model, parent, factory, service_context)[source]¶A collection manager provides access to resource collection instances,
which can be iterated and filtered. The manager exposes some
convenience functions that are also found on resource collections,
such as all()
and
filter()
.
Get all items:
>>> for bucket in s3.buckets.all():
... print(bucket.name)
Get only some items via filtering:
>>> for queue in sqs.queues.filter(QueueNamePrefix='AWS'):
... print(queue.url)
Get whole pages of items:
>>> for page in s3.Bucket('boto3').objects.pages():
... for obj in page:
... print(obj.key)
A collection manager is not iterable. You must call one of the
methods that return a ResourceCollection
before trying
to iterate, slice, or convert to a list.
See the Collections guide for a high-level overview of collections, including when remote service requests are performed.
ServiceResource
) -- The collection's parent resourceResourceFactory
) -- The resource factory to create new resourcesServiceContext
) -- Context about the AWS serviceall
()[source]¶Get all items from the collection, optionally with a custom page size and item count limit.
This method returns an iterable generator which yields individual resource instances. Example use:
# Iterate through items
>>> for queue in sqs.queues.all():
... print(queue.url)
'https://url1'
'https://url2'
# Convert to list
>>> queues = list(sqs.queues.all())
>>> len(queues)
2
filter
(**kwargs)[source]¶Get items from the collection, passing keyword arguments along as parameters to the underlying service operation, which are typically used to filter the results.
This method returns an iterable generator which yields individual resource instances. Example use:
# Iterate through items
>>> for queue in sqs.queues.filter(Param='foo'):
... print(queue.url)
'https://url1'
'https://url2'
# Convert to list
>>> queues = list(sqs.queues.filter(Param='foo'))
>>> len(queues)
2
ResourceCollection
iterator
(**kwargs)[source]¶Get a resource collection iterator from this manager.
ResourceCollection
limit
(count)[source]¶Return at most this many resources.
>>> for bucket in s3.buckets.limit(5):
... print(bucket.name)
'bucket1'
'bucket2'
'bucket3'
'bucket4'
'bucket5'
ResourceCollection
page_size
(count)[source]¶Fetch at most this many resources per service request.
>>> for obj in s3.Bucket('boto3').objects.page_size(100):
... print(obj.key)
ResourceCollection
pages
()[source]¶A generator which yields pages of resource instances after doing the appropriate service operation calls and handling any pagination on your behalf. Non-paginated calls will return a single page of items.
Page size, item limit, and filter parameters are applied if they have previously been set.
>>> bucket = s3.Bucket('boto3')
>>> for page in bucket.objects.pages():
... for obj in page:
... print(obj.key)
'key1'
'key2'
ServiceResource
)boto3.resources.collection.
ResourceCollection
(model, parent, handler, **kwargs)[source]¶Represents a collection of resources, which can be iterated through, optionally with filtering. Collections automatically handle pagination for you.
See Collections for a high-level overview of collections, including when remote service requests are performed.
Collection
) -- Collection modelServiceResource
) -- The collection's parent resourceResourceHandler
) -- The resource response handler used to create resource
instancesall
()[source]¶Get all items from the collection, optionally with a custom page size and item count limit.
This method returns an iterable generator which yields individual resource instances. Example use:
# Iterate through items
>>> for queue in sqs.queues.all():
... print(queue.url)
'https://url1'
'https://url2'
# Convert to list
>>> queues = list(sqs.queues.all())
>>> len(queues)
2
filter
(**kwargs)[source]¶Get items from the collection, passing keyword arguments along as parameters to the underlying service operation, which are typically used to filter the results.
This method returns an iterable generator which yields individual resource instances. Example use:
# Iterate through items
>>> for queue in sqs.queues.filter(Param='foo'):
... print(queue.url)
'https://url1'
'https://url2'
# Convert to list
>>> queues = list(sqs.queues.filter(Param='foo'))
>>> len(queues)
2
ResourceCollection
limit
(count)[source]¶Return at most this many resources.
>>> for bucket in s3.buckets.limit(5):
... print(bucket.name)
'bucket1'
'bucket2'
'bucket3'
'bucket4'
'bucket5'
ResourceCollection
page_size
(count)[source]¶Fetch at most this many resources per service request.
>>> for obj in s3.Bucket('boto3').objects.page_size(100):
... print(obj.key)
ResourceCollection
pages
()[source]¶A generator which yields pages of resource instances after doing the appropriate service operation calls and handling any pagination on your behalf. Non-paginated calls will return a single page of items.
Page size, item limit, and filter parameters are applied if they have previously been set.
>>> bucket = s3.Bucket('boto3')
>>> for page in bucket.objects.pages():
... for obj in page:
... print(obj.key)
'key1'
'key2'
ServiceResource
)