EventApiDestination
An EventBridge API destination. |
|
- class EventApiDestination(*args, **kwargs)[source]
An EventBridge API destination.
- Parameters:
client (CatalogClient, optional) – A
CatalogClient
instance to use for requests to the Descartes Labs catalog. Theget_default_client()
will be used if not set.kwargs (dict) – With the exception of readonly attributes (
created
andmodified
) and with the exception of properties (ATTRIBUTES
,is_modified
, andstate
), any attribute listed below can also be used as a keyword argument. Also seeATTRIBUTES
.
Methods:
delete
(id[, client])Delete the catalog object with the given
id
.exists
(id[, client, headers])Checks if an object exists in the Descartes Labs catalog.
get
([id, namespace, name, client, ...])Get an existing EventApiDestination from the Descartes Labs catalog.
get_many
(ids[, ignore_missing, client, ...])Get existing objects from the Descartes Labs catalog.
get_or_create
([id, namespace, name, client])Get an existing object from the Descartes Labs catalog or create a new object.
namespace_id
(namespace_id[, client])Generate a fully namespaced id.
reload
([request_params, headers])Reload all attributes from the Descartes Labs catalog.
save
([request_params, headers])Saves this object to the Descartes Labs catalog.
search
([client, request_params, headers])A search query for all event api destinations.
serialize
([modified_only, jsonapi_format])Serialize the catalog object into json.
update
([ignore_errors])Update multiple attributes at once using the given keyword arguments.
user_can_read
([auth])Check if the authenticated user is an owner, a writer, or a reader and has permissions to read this object.
user_can_write
([auth])Check if the authenticated user is an owner or a writer and has permissions to modify this object.
user_is_owner
([auth])Check if the authenticated user is an owner, and can perform actions such as changing ACLs or deleting this object.
Attributes:
The ARN of the event api destination.
The API_KEY header name.
The API_KEY header value.
The ARN of the connection.
The authorization type for this api destination.
The BASIC password for this api destination.
The BASIC username for this api destination.
A list of connection parameters for request bodies to be sent on requests on the connection.
A description with further details on this event connection.
A list of connection parameters for headers to be sent on requests on the connection.
The name of the connection for this api destination.
A list of connection parameters for OAuth request body values to be sent on OAuth requests on the connection.
The client ID for OAuth authorization for this connection.
The client secret for OAuth authorization for this connection.
The OAUTH authorization endpoint for this connection.
A list of connection parameters for OAuth request headers to be sent on OAuth requests on the connection.
The HTTP method for OAuth authorization for this connection.
A list of connection parameters for OAuth request query strings to be sent on OAuth requests on the connection.
A list of connection parameters for query strings to be sent on requests on the connection.
The point in time this object was created.
A description with further details on this event api destination.
The endpoint for this api destination.
A dictionary of up to 50 key/value pairs.
A unique identifier for this object.
The maximum number of invocations per second for this api destination.
Whether this is a Descartes Labs catalog core event api destination.
Whether any attributes were changed (see
state
).The HTTP method for this api destination.
The point in time this object was last modified.
The name of this event api destination.
The namespace of this event api destination.
User, group, or organization IDs that own this object.
User, email, group, or organization IDs that can read this object.
The state of this catalog object.
A list of up to 32 tags, each up to 1000 bytes long.
The value of the attribute is checked against the given type.
User, group, or organization IDs that can edit this object.
- classmethod delete(id, client=None)
Delete the catalog object with the given
id
.- Parameters:
id (str) – The id of the object to be deleted.
client (CatalogClient, optional) – A
CatalogClient
instance to use for requests to the Descartes Labs catalog. Theget_default_client()
will be used if not set.
- Returns:
True
if this object was successfully deleted.False
if the object was not found.- Return type:
bool
- Raises:
ConflictError – If the object has related objects (bands, images) that exist.
ClientError or ServerError – Spurious exception that can occur during a network request.
Example
>>> Image.delete('my-image-id')
There is also an instance
delete
method that can be used to delete an object. It accepts no parameters and does not return anything. Once deleted, you cannot use the catalog object and should release any references.
- classmethod exists(id, client=None, headers=None)
Checks if an object exists in the Descartes Labs catalog.
- Parameters:
id (str) – The id of the object.
client (CatalogClient, optional) – A
CatalogClient
instance to use for requests to the Descartes Labs catalog. Theget_default_client()
will be used if not set.
- Returns:
Returns
True
if the givenid
represents an existing object in the Descartes Labs catalog andFalse
if not.- Return type:
bool
- Raises:
ClientError or ServerError – Spurious exception that can occur during a network request.
- classmethod get(id=None, namespace=None, name=None, client=None, request_params=None, headers=None)[source]
Get an existing EventApiDestination from the Descartes Labs catalog.
If the EventApiDestination is found, it will be returned in the
SAVED
state. Subsequent changes will put the instance in theMODIFIED
state, and you can usesave()
to commit those changes and update the Descartes Labs catalog object. Also see the example forsave()
.Exactly one of the
id
andname
parameters must be specified. Ifname
is specified, it is used together with thenamespace
parameters to form the correspondingid
.- Parameters:
id (str, optional) – The id of the object you are requesting. Required unless
name
is supplied. May not be specified ifname
is specified.namespace (str, optional) – The namespace of the EventApiDestination you wish to retrieve. Defaults to the user’s org name (if any) plus the unique user hash. Ignored unless
name
is specified.name (str, optional) – The name of the EventApiDestination you wish to retrieve. Required if
id
is not specified. May not be specified ifid
is specified.client (CatalogClient, optional) – A
CatalogClient
instance to use for requests to the Descartes Labs catalog. Theget_default_client()
will be used if not set.
- Returns:
The object you requested, or
None
if an object with the givenid
does not exist in the Descartes Labs catalog.- Return type:
CatalogObject
or None- Raises:
ClientError or ServerError – Spurious exception that can occur during a network request.
- classmethod get_many(ids, ignore_missing=False, client=None, request_params=None, headers=None)
Get existing objects from the Descartes Labs catalog.
All returned Descartes Labs catalog objects will be in the
SAVED
state. Also seeget()
.For bands, if you request a specific band type, for example
SpectralBand.get_many()
, you will only receive that type. UseBand.get_many()
to receive any type.- Parameters:
ids (list(str)) – A list of identifiers for the objects you are requesting.
ignore_missing (bool, optional) – Whether to raise a
NotFoundError
exception if any of the requested objects are not found in the Descartes Labs catalog.False
by default which raises the exception.client (CatalogClient, optional) – A
CatalogClient
instance to use for requests to the Descartes Labs catalog. Theget_default_client()
will be used if not set.
- Returns:
List of the objects you requested in the same order.
- Return type:
list(
CatalogObject
)- Raises:
NotFoundError – If any of the requested objects do not exist in the Descartes Labs catalog and
ignore_missing
isFalse
.ClientError or ServerError – Spurious exception that can occur during a network request.
- classmethod get_or_create(id=None, namespace=None, name=None, client=None, **kwargs)[source]
Get an existing object from the Descartes Labs catalog or create a new object.
If the Descartes Labs catalog object is found, and the remainder of the arguments do not differ from the values in the retrieved instance, it will be returned in the
SAVED
state.If the Descartes Labs catalog object is found, and the remainder of the arguments update one or more values in the instance, it will be returned in the
MODIFIED
state.If the Descartes Labs catalog object is not found, it will be created and the state will be
UNSAVED
. Also see the example forsave()
.- Parameters:
id (str, optional) – The id of the object you are requesting. Required unless
name
is supplied. May not be specified ifname
is specified.namespace (str, optional) – The namespace of the EventApiDestination you wish to retrieve. Defaults to the user’s org name (if any) plus the unique user hash. Ignored unless
name
is specified.name (str, optional) – The name of the EventApiDestination you wish to retrieve. Required if
id
is not specified. May not be specified ifid
is specified.client (CatalogClient, optional) – A
CatalogClient
instance to use for requests to the Descartes Labs catalog. Theget_default_client()
will be used if not set.kwargs (dict, optional) – With the exception of readonly attributes (
created
,modified
), any attribute of a catalog object can be set as a keyword argument (Also seeATTRIBUTES
).
- Returns:
The requested catalog object that was retrieved or created.
- Return type:
- classmethod namespace_id(namespace_id, client=None)[source]
Generate a fully namespaced id.
- Parameters:
namespace_id (str or None) – The unprefixed part of the id that you want prefixed.
client (CatalogClient, optional) – A
CatalogClient
instance to use for requests to the Descartes Labs catalog. Theget_default_client()
will be used if not set.
- Returns:
The fully namespaced id.
- Return type:
str
Example
>>> namespace = EventApiDestination.namespace_id("myproject") 'myorg:myproject'
- reload(request_params=None, headers=None)
Reload all attributes from the Descartes Labs catalog.
Refresh the state of this catalog object from the object in the Descartes Labs catalog. This may be necessary if there are concurrent updates and the object in the Descartes Labs catalog was updated from another client. The instance state must be in the
SAVED
state.If you want to revert a modified object to its original one, you should use
get()
on the object class with the object’sid
.- Raises:
ValueError – If the catalog object is not in the
SAVED
state.DeletedObjectError – If this catalog object was deleted.
ClientError or ServerError – Spurious exception that can occur during a network request.
- save(request_params=None, headers=None)
Saves this object to the Descartes Labs catalog.
If this instance was created using the constructor, it will be in the
UNSAVED
state and is considered a new Descartes Labs catalog object that must be created. If the catalog object already exists in this case, this method will raise aBadRequestError
.If this instance was retrieved using
get()
,get_or_create()
or any other way (for example as part of asearch()
), and any of its values were changed, it will be in theMODIFIED
state and the existing catalog object will be updated.If this instance was retrieved using
get()
,get_or_create()
or any other way (for example as part of asearch()
), and none of its values were changed, it will be in theSAVED
state, and if norequest_params
parameter is given, nothing will happen.- Parameters:
request_params (dict, optional) – A dictionary of attributes that should be sent to the catalog along with attributes already set on this object. Empty by default. If not empty, and the object is in the
SAVED
state, it is updated in the Descartes Labs catalog even though no attributes were modified.headers (dict, optional) – A dictionary of header keys and values to be sent with the request.
- Raises:
ConflictError – If you’re trying to create a new object and the object with given
id
already exists in the Descartes Labs catalog.BadRequestError – If any of the attribute values are invalid.
DeletedObjectError – If this catalog object was deleted.
ClientError or ServerError – Spurious exception that can occur during a network request.
- classmethod search(client=None, request_params=None, headers=None)[source]
A search query for all event api destinations.
Return an
EventApiDestinationSearch
instance for searching event api destinations in the Descartes Labs catalog.- Parameters:
client (
CatalogClient
, optional) – ACatalogClient
instance to use for requests to the Descartes Labs catalog.- Returns:
An instance of the
EventApiDestinationSearch
class- Return type:
EventApiDestinationSearch
Example
>>> from descarteslabs.catalog import EventApiDestination >>> search = EventApiDestination.search().limit(10) >>> for result in search: ... print(result.name)
- serialize(modified_only=False, jsonapi_format=False)
Serialize the catalog object into json.
- Parameters:
modified_only (bool, optional) – Whether only modified attributes should be serialized.
False
by default. If set toTrue
, only those attributes that were modified since the last time the catalog object was retrieved or saved will be included.jsonapi_format (bool, optional) – Whether to use the
data
element for catalog objects.False
by default. When set toFalse
, the serialized data will directly contain the attributes of the catalog object. If set toTrue
, the serialized data will follow the exact JSONAPI with a top-leveldata
element which containsid
,type
, andattributes
. The latter will contain the attributes of the catalog object.
- update(ignore_errors=False, **kwargs)
Update multiple attributes at once using the given keyword arguments.
- Parameters:
ignore_errors (bool, optional) –
False
by default. When set toTrue
, it will suppressAttributeValidationError
andAttributeError
. Any given attribute that causes one of these two exceptions will be ignored, all other attributes will be set to the given values.- Raises:
AttributeValidationError – If one or more of the attributes being updated are immutable.
AttributeError – If one or more of the attributes are not part of this catalog object.
DeletedObjectError – If this catalog object was deleted.
- user_can_read(auth=None)
Check if the authenticated user is an owner, a writer, or a reader and has permissions to read this object.
Note it is kind of silly to call this method unless a non-default auth object is provided, because the default authorized user must have read permission in order to even retrieve this object.
- Parameters:
auth (Auth, optional) – The auth object to use for the check. If not provided, the default auth object will be used.
- Returns:
True if the user can read the object, False otherwise.
- Return type:
bool
- user_can_write(auth=None)
Check if the authenticated user is an owner or a writer and has permissions to modify this object.
- Parameters:
auth (Auth, optional) – The auth object to use for the check. If not provided, the default auth object will be used.
- Returns:
True if the user can modify the object, False otherwise.
- Return type:
bool
- user_is_owner(auth=None)
Check if the authenticated user is an owner, and can perform actions such as changing ACLs or deleting this object.
- Parameters:
auth (Auth, optional) – The auth object to use for the check. If not provided, the default auth object will be used.
- Returns:
True if the user is an owner of the object, False otherwise.
- Return type:
bool
- ATTRIBUTES = ('namespace', 'name', 'description', 'is_core', 'endpoint', 'method', 'invocation_rate', 'arn', 'connection_name', 'connection_description', 'connection_header_parameters', 'connection_query_string_parameters', 'connection_body_parameters', 'connection_authorization_type', 'connection_api_key_name', 'connection_api_key_value', 'connection_basic_username', 'connection_basic_password', 'connection_oauth_endpoint', 'connection_oauth_method', 'connection_oauth_client_id', 'connection_oauth_client_secret', 'connection_oauth_header_parameters', 'connection_oauth_query_string_parameters', 'connection_oauth_body_parameters', 'connection_arn', 'owners', 'readers', 'writers', 'extra_properties', 'tags', 'id', 'created', 'modified')
- arn
The ARN of the event api destination.
- Type:
str
- connection_api_key_name
The API_KEY header name.
- Type:
str
- connection_api_key_value
The API_KEY header value.
- Type:
str
- connection_arn
The ARN of the connection.
- Type:
str
- connection_authorization_type
The authorization type for this api destination.
- Type:
str
- connection_basic_password
The BASIC password for this api destination.
- Type:
str
- connection_basic_username
The BASIC username for this api destination.
- Type:
str
- connection_body_parameters
A list of connection parameters for request bodies to be sent on requests on the connection.
- Type:
list(EventConnectionParameter)
- connection_description
A description with further details on this event connection.
The description can be up to 80,000 characters and is used by
Search.find_text()
.Searchable
- Type:
str, optional
- connection_header_parameters
A list of connection parameters for headers to be sent on requests on the connection.
- Type:
list(EventConnectionParameter)
- connection_name
The name of the connection for this api destination.
- Type:
str
- connection_oauth_body_parameters
A list of connection parameters for OAuth request body values to be sent on OAuth requests on the connection.
- Type:
list(EventConnectionParameter)
- connection_oauth_client_id
The client ID for OAuth authorization for this connection.
- Type:
str
- connection_oauth_client_secret
The client secret for OAuth authorization for this connection.
- Type:
str
- connection_oauth_endpoint
The OAUTH authorization endpoint for this connection.
- Type:
str
- connection_oauth_header_parameters
A list of connection parameters for OAuth request headers to be sent on OAuth requests on the connection.
- Type:
list(EventConnectionParameter)
- connection_oauth_method
The HTTP method for OAuth authorization for this connection.
- Type:
str
- connection_oauth_query_string_parameters
A list of connection parameters for OAuth request query strings to be sent on OAuth requests on the connection.
- Type:
list(EventConnectionParameter)
- connection_query_string_parameters
A list of connection parameters for query strings to be sent on requests on the connection.
- Type:
list(EventConnectionParameter)
- created
The point in time this object was created.
Filterable, sortable.
- Type:
datetime, readonly
- description
A description with further details on this event api destination.
The description can be up to 80,000 characters and is used by
Search.find_text()
.Searchable
- Type:
str, optional
- endpoint
The endpoint for this api destination. May contain
*
characters to be replaced with path parameters from the rule target.- Type:
str
- extra_properties
A dictionary of up to 50 key/value pairs.
The keys of this dictionary must be strings, and the values of this dictionary can be strings or numbers. This allows for more structured custom metadata to be associated with objects.
- Type:
dict, optional
- id
A unique identifier for this object.
Note that if you pass a string that does not begin with your Descartes Labs user organization ID, it will be prepended to your
id
with a:
as separator. If you are not part of an organization, your user ID is used. Once set, it cannot be changed.- Type:
str, immutable
- invocation_rate
The maximum number of invocations per second for this api destination.
- Type:
int
- is_core
Whether this is a Descartes Labs catalog core event api destination.
A core event api destination is an event api destination that is fully managed by Descartes Labs. By default this value is
False
and you must have a special permission (descarteslabs:core:create
) to set it toTrue
.Filterable, sortable.
- Type:
bool, optional
- property is_modified
Whether any attributes were changed (see
state
).True
if any of the attribute values changed since the last time this catalog object was retrieved or saved.False
otherwise.Note that assigning an identical value does not affect the state.
- Type:
bool
- method
The HTTP method for this api destination.
- Type:
str
- modified
The point in time this object was last modified.
Filterable, sortable.
- Type:
datetime, readonly
- name
The name of this event api destination.
All event_api_destinations are stored and indexed by name. Names are allowed a restricted alphabet (
a-zA-Z0-9_-
).Searchable, sortable.
- Type:
str
- namespace
The namespace of this event api destination.
All event api destinations are stored and indexed under a namespace. Namespaces are allowed a restricted alphabet (
a-zA-Z0-9:._-
), and must begin with the user’s org name, or their unique user hash if the user has no org. The required prefix is seperated from the rest of the namespace name (if any) by a:
. If not provided, the namespace will default to the users org (if any) and the unique user hash.Searchable, sortable.
- Type:
str
- owners
User, group, or organization IDs that own this object.
Defaults to [
user:current_user
,org:current_org
]. The owner can edit, delete, and change access to this object. See this note.Filterable.
- Type:
list(str), optional
- readers
User, email, group, or organization IDs that can read this object.
Will be empty by default. This attribute is only available in full to the
owners
of the object. See this note.- Type:
list(str), optional
- property state
The state of this catalog object.
- Type:
- tags
A list of up to 32 tags, each up to 1000 bytes long.
The tags may support the classification and custom filtering of objects.
Filterable.
- Type:
list, optional
- v1_properties
The value of the attribute is checked against the given type.
- Parameters:
attribute_type (type) – The type of the attribute.
coerce (bool, optional) – Whether a non-conforming value should be coerced to that type.
False
by default.**kwargs (optional) – See
Attribute
.
- writers
User, group, or organization IDs that can edit this object.
Writers will also have read permission. Writers will be empty by default. See note below. This attribute is only available in full to the
owners
of the object. See this note.- Type:
list(str), optional
- class EventApiDestinationCollection(iterable=None, item_type=None)[source]
Methods:
append
(x)Append x to the end of this
Collection
.extend
(x)Extend this
Collection
by appending elements from the iterable.filter
(predicate)Returns a
Collection
filtered by predicate.groupby
(*predicates)Groups items by predicates.
map
(f)Returns a
Collection
off
applied to each item.sort
(field[, ascending])Returns a
Collection
, sorted by the given field and direction.sorted
(*predicates, **reverse)Returns a
Collection
, sorted by predicates in ascending order.Attributes:
Any operations chained onto
each
(attribute access, item access, and calls) are applied to each item in theCollection
.- append(x)
Append x to the end of this
Collection
.The type of the item must match the type of the collection.
- Parameters:
x (Any) – Add an item to the collection
- extend(x)
Extend this
Collection
by appending elements from the iterable.The type of the items in the list must all match the type of the collection.
- Parameters:
x (List[Any]) – Extend a collection with the items from the list.
- filter(predicate)
Returns a
Collection
filtered by predicate.Predicate can either be a
callable
or anExpression
from Properties.If the predicate is a
callable
,filter()
will return all items for whichpredicate(item)
isTrue
.If the predicate is an
Expression
,filter()
will return all items for whichpredicate.evaluate(item)
isTrue
.- Parameters:
predicate (callable or Expression) – Either a callable or a Properties
Expression
which is called or evaluated for each item in the list.- Returns:
A new collection with only those items for which the predicate returned or evaluated to
True
.- Return type:
Collection
- groupby(*predicates)
Groups items by predicates.
Groups items by predicates and yields tuple of
(group, items)
for each group, whereitems
is aCollection
.Each predicate can be a key function, or a string of dot-chained attributes to use as sort keys.
- Parameters:
predicates (callable or str) – Any positional arguments are predicates. If the predicate is a string, it denotes an attribute for each element, potentially with levels separated by a dot. If the predicate is a callable, it must return the value to sort by for each given element.
- Yields:
Tuple[str, Collection] – A tuple of
(group, Collection)
for each group.
Examples
>>> import collections >>> FooBar = collections.namedtuple("FooBar", ["foo", "bar"]) >>> c = Collection([FooBar("a", True), FooBar("b", False), FooBar("a", False)])
>>> for group, items in c.groupby("foo"): ... print(group) ... print(items) a Collection([FooBar(foo='a', bar=True), FooBar(foo='a', bar=False)]) b Collection([FooBar(foo='b', bar=False)]) >>> for group, items in c.groupby("bar"): ... print(group) ... print(items) False Collection([FooBar(foo='b', bar=False), FooBar(foo='a', bar=False)]) True Collection([FooBar(foo='a', bar=True)])
- map(f)
Returns a
Collection
off
applied to each item.- Parameters:
f (callable) – Apply function
f
to each element of the collection and return the result as a collection.- Returns:
A collection with the results of the function
f
applied to each element of the original collection.- Return type:
Collection
- sort(field, ascending=True)
Returns a
Collection
, sorted by the given field and direction.- Parameters:
field (str) – The name of the field to sort by
ascending (bool) – Sorts results in ascending order if True (the default), and in descending order if False.
- Returns:
The sorted collection.
- Return type:
Collection
Example
>>> from descarteslabs.catalog import Product >>> collection = Product.search().collect() >>> sorted_collection = collection.sort("created", ascending=False) >>> sorted_collection
- sorted(*predicates, **reverse)
Returns a
Collection
, sorted by predicates in ascending order.Each predicate can be a key function, or a string of dot-chained attributes to use as sort keys. The reverse flag returns results in descending order.
- Parameters:
predicates (callable or str) – Any positional arguments are predicates. If the predicate is a string, it denotes an attribute for each element, potentially with levels separated by a dot. If the predicate is a callable, it must return the value to sort by for each given element.
reverse (bool) – The sort is ascending by default, by setting
reverse
toTrue
, the sort will be descending.
- Returns:
The sorted collection.
- Return type:
Collection
Examples
>>> import collections >>> FooBar = collections.namedtuple("FooBar", ["foo", "bar"]) >>> X = collections.namedtuple("X", "x") >>> c = Collection([FooBar(1, X("one")), FooBar(2, X("two")), FooBar(3, X("three"))])
>>> c.sorted("foo") Collection([FooBar(foo=1, bar=X(x='one')), FooBar(foo=2, bar=X(x='two')), FooBar(foo=3, bar=X(x='three'))]) >>> c.sorted("bar.x") Collection([FooBar(foo=1, bar=X(x='one')), FooBar(foo=3, bar=X(x='three')), FooBar(foo=2, bar=X(x='two'))])
- property each
Any operations chained onto
each
(attribute access, item access, and calls) are applied to each item in theCollection
.- Yields:
Any – The result of an item with all operations following
each
applied to it.
Notes
Add
combine()
at the end of the operations chain to combine the results into a list by default, or any container type passed intocombine()
Use
pipe(f, *args, **kwargs)
to yieldf(x, *args, **kwargs)
for each itemx
yielded by the preceeding operations chain
Examples
>>> c = Collection(["one", "two", "three", "four"]) >>> for x in c.each.capitalize(): ... print(x) One Two Three Four >>> c.each.capitalize()[:2] 'On' 'Tw' 'Th' 'Fo' >>> c.each.capitalize().pipe(len) 3 3 5 4 >>> list(c.each.capitalize().pipe(len).combine(set)) [3, 4, 5]