Components

Resource

Methods

Component.__init__(manager, data)

Resource initializer.

Parameters
  • manager – The manager this resource belongs to

  • data – The raw json data

Component.add_tag(name: str) → None

Add a new tag.

Parameters

name (str) – Name of the tag

Component.add_tags(names: Iterable[str]) → None

Add multiple tags.

Note

We use the provided name also as the slug. When the resource is returned from the server the next time it will be slugified.

Parameters

names (Iterable[str]) – Iterable with names such as a list or set

Component.set_tags(names: Iterable[str])

Replace the current tags.

Note

We use the provided names also as the slugs. When the resource is returned from the server the next time it will be slugified.

Component.del_tag(name: str = None, slug: str = None) → None

Delete a tag.

We can delete a tag by using the slug or actual name. Names and slugs are case insensitive.

Parameters
  • name (str) – name to remove

  • slug (str) – slug to remove

Raises

KeyError – if tag does not exist

Component.has_tag(name: str = None, slug: str = None) → bool

Check if a tag exists by name or slug.

Tags and slugs are case insensitive.

Parameters
  • name (str) – Name of the tag

  • slug (str) – Slug for the tag

Returns

If the tag exists

Return type

bool

Component.update()

Posts the values in the resource to the server.

Example:

# Change an attribute and save the resource
>> resource.value = something
>> updated_resource = resource.update()
Returns

The updated resource from the server

Return type

Resource

Component.get(name) → Any

Safely obtain any attribute name for the resource

Parameters

name (str) – Key name in json response

Returns

Value from the raw json response. If the key doesn’t exist None is returned.

Component.delete() → None

Deletes the resource from the server.

Raises

HTTPException if the resource don't exist.

Attributes

Component.attrs

The raw json response from the server

Type

dict

Component.id

The unique ID of the component

Type

int

Component.name

Get or set name of the component

Type

str

Component.description

Get or set component description

Type

str

Get or set http link to the component

Type

str

Component.status

Get or set status id of the component (see enums)

Type

int

Component.status_name

Human readable status representation

Type

str

Component.order

Get or set order of the component in a group

Type

int

Component.group_id

Get or set the component group id

Type

int

Component.enabled

Get or set enabled state

Type

bool

Component.tags

name`` tag dictionary.

Example:

>> component.tags
{'another-test-tag': 'Another Test Tag', 'test-tag': 'Test Tag'}

Also see add_tag, add_tags, set_tags, del_tag and has_tag methods.

Type

dict

Type

Get the raw ``slug

Component.tag_names

Get the tag names as a list

Type

List[str]

Component.tag_slugs

Get the tag slugs as a list

Type

List[str]

Component.created_at

When the component was created

Type

datetime

Component.updated_at

Last time the component was updated

Type

datetime

Manager

Methods

ComponentManager.__init__(http_client: cachetclient.httpclient.HttpClient)

Manager initializer.

Parameters

http_client – The httpclient

ComponentManager.create(*, name: str, status: int, description: str = None, link: str = None, order: int = None, group_id: int = None, enabled: bool = True, tags: Iterable[str] = None)

Create a component.

Keyword Arguments
  • name (str) – Name of the component

  • status (int) – Status if of the component (see enums module)

  • description (str) – Description of the component (required)

  • link (str) – Link to the component

  • order (int) – Order of the component in its group

  • group_id (int) – The group it belongs to

  • enabled (bool) – Enabled status

  • tags (Iterable[str]) – A list, set or other iterable containing string tags

Returns

Component instance

ComponentManager.update(component_id: int, *, status: int, name: str = None, description: str = None, link: str = None, order: int = None, group_id: int = None, enabled: bool = None, tags: Iterable[str] = None, **kwargs) → cachetclient.v1.components.Component

Update a component by id.

Parameters

component_id (int) – The component to update

Keyword Arguments
  • status (int) – Status of the component (see enums)

  • name (str) – New name

  • description (str) – New description

  • link (str) – Link to component

  • order (int) – Order in component group

  • group_id (int) – Component group id

  • enabled (bool) – Enable status of component

  • tags (Iterable[str]) – Iterable of tag strings

Returns

Updated Component from server

ComponentManager.list(page: int = 1, per_page: int = 20) → Generator[cachetclient.v1.components.Component, None, None]

List all components

Keyword Arguments
  • page (int) – The page to start listing

  • per_page (int) – Number of entries per page

Returns

Generator of Component instances

ComponentManager.get(component_id: int) → cachetclient.v1.components.Component

Get a component by id

Parameters

component_id (int) – Id of the component

Returns

Component instance

Raises

HttpError – if not found

ComponentManager.count() → int

Count the number of components

Returns

Total number of components

Return type

int

ComponentManager.delete(component_id: int) → None

Delete a component

Parameters

component_id (int) – Id of the component

Raises

HTTPError – if component do not exist

ComponentManager.instance_from_dict(data: dict) → cachetclient.base.Resource

Creates a resource instance from a dictionary.

This doesn’t hit any endpoints in cachet, but rather enables us to create a resource class instance from dictionary data. This can be useful when caching data from cachet in memcache or databases.

Parameters

data (dict) – dictionary containing the instance data

Returns

The resource class instance

Return type

Resource

ComponentManager.instance_from_json(data: str) → cachetclient.base.Resource

Creates a resource instance from a json string.

This doesn’t hit any endpoints in cachet, but rather enables us to create a resource class instance from json data. This can be useful when caching data from cachet in memcache or databases.

Parameters

data (str) – json string containing the instance data

Returns

The resource class instance

Return type

Resource

ComponentManager.instance_list_from_json(data: str) → List[cachetclient.base.Resource]

Creates a resource instance list from a json string.

This doesn’t hit any endpoints in cachet, but rather enables us to create a resource class instances from json data. This can be useful when caching data from cachet in memcache or databases.

Parameters

data (str) – json string containing the instance data

Returns

The resource class instance

Return type

Resource

Raises

ValueError – if json data do not deserialize into a list

Attributes

ComponentManager.path = 'components'
ComponentManager.resource_class = <class 'cachetclient.v1.components.Component'>