# Context

The context represents the world.

| Source                                                                                                          | Added |
| --------------------------------------------------------------------------------------------------------------- | ----- |
| [Link](https://github.com/pyblish/pyblish/blob/6e9bfce6254ea56411af857afa49423a57f7b425/pyblish/plugin.py#L542) | 0.1.6 |

Inherits [AbstractEntity](/pyblish.api/abstractentity.md)

## Public Functions

|   Output | Method                                                                                |
| -------: | ------------------------------------------------------------------------------------- |
| Instance | [.create\_instance](/pyblish.api/context/context.create_instance.md)(str, \*\*kwargs) |

4 functions inherited from [AbstractEntity](/pyblish.api/abstractentity.md)

## Description

The context encapsulates one or more [Instance](/pyblish.api/instance.md)'s along with information about the current execution environment, such as the current user and time of day. Publishing is performed by iterating over the members of a context.

```python
# Psuedo-code
for plugin in plugins:
  for instance in context:
     plugin.process(instance)
```

## Examples

```python
# Creating a context
#
# The context is normally created for you by a user interface or
# through convenience functions, but can be helpful to manually
# create for debugging purposes.

import pyblish.api as pyblish
context = pyblish.Context()
```

```python
# Creating instances from a context
#
# Instances can be created directly or through a context. When
# created through a context, the context is automatically set
# as the parent of the newly created instance.

import pyblish.api as pyblish
context = pyblish.Context()
instanceA = context.create_instance(name="MyInstanceA")
instanceB = pyblish.Instance(name="MyInstanceB", parent=context)

print("The context contains these instances:")
for instance in context:
    print(instance)
# MyInstanceA
# MyInstanceB
```

```python
# Setting data on a context
# 
# Both Instance and Context inherit from AbstractEntity which
# provides the mechanism for modifying data.

import pyblish.api as pyblish
context = pyblish.Context()
data = context.data
context.data["hostname"] = "localhost"
assert "hostname" in context.data is True
context.data.pop("hostname")
assert "hostname" in context.data is False
```

{{ file.mtime }}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://api.pyblish.com/pyblish.api/context.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
