# ModelPackage

```python
class ModelPackage
```

Represents an MXQ package (.mxqpkg) that packs multiple MXQ files into a single file.

Opens the package once and creates [Model](<https://docs.mobilint.com/runtime/kr/v1.6/api/python/Model/index.md>) objects from its MXQ entries without unpacking it. Prefer this class to Model(path, entry\_name) when creating many models from the same package, because the package index is read only once.

Models created from a [ModelPackage](<https://docs.mobilint.com/runtime/kr/v1.6/api/python/ModelPackage/index.md>) do not depend on it, so the [ModelPackage](<https://docs.mobilint.com/runtime/kr/v1.6/api/python/ModelPackage/index.md>) may be discarded while the models are still in use.

> [!WARNING]
>
> The package file is read again by create\_model and load\_entry, and by the created models when they are launched. Moving or deleting the file before then makes those calls fail, and modifying it may make the models produce wrong results.

## Methods

| Name | Description |
| --- | --- |
| [`__init__`](<#init>) | Opens the specified MXQ package file. |
| [`create_model`](<#create-model>) | Creates a [Model](<https://docs.mobilint.com/runtime/kr/v1.6/api/python/Model/index.md>) object from an MXQ entry in the package. |
| [`get_path`](<#get-path>) | Returns the path to the MXQ package file. |
| [`get_entry_names`](<#get-entry-names>) | Returns the names of all entries in the package, in the order they are stored. |
| [`load_entry`](<#load-entry>) | Reads the payload of a non-MXQ entry in the package into memory. |

### \_\_init\_\_

```python
def __init__(self, path: str)
```

Opens the specified MXQ package file.

Reads and validates the package index. The MXQ entries are not loaded until create\_model is called.

**Parameters**

- `path` *\[in\]* — The path to the MXQ package file.

### create\_model

```python
def create_model(
    self, entry_name: str, model_config: Optional[ModelConfig] = None
) -> Model
```

Creates a [Model](<https://docs.mobilint.com/runtime/kr/v1.6/api/python/Model/index.md>) object from an MXQ entry in the package.

> [!NOTE]
>
> The created [Model](<https://docs.mobilint.com/runtime/kr/v1.6/api/python/Model/index.md>) object must be launched before performing inference. See [Model.launch](<https://docs.mobilint.com/runtime/kr/v1.6/api/python/Model/#launch>) for more details.

**Parameters**

- `entry_name` *\[in\]* — The name of the MXQ entry in the package (e.g. "block\_0\_expert\_0.mxq").
- `model_config` *\[in\]* — The configuration settings to initialize the [Model](<https://docs.mobilint.com/runtime/kr/v1.6/api/python/Model/index.md>). If None, the model is initialized in auto-core mode.

**Returns**

The created [Model](<https://docs.mobilint.com/runtime/kr/v1.6/api/python/Model/index.md>) object.

### get\_path

```python
def get_path(self) -> str
```

Returns the path to the MXQ package file.

**Returns**

The MXQ package file path.

### get\_entry\_names

```python
def get_entry_names(self) -> List[str]
```

Returns the names of all entries in the package, in the order they are stored.

The names include entries that are not MXQ files, such as a manifest. Only MXQ entries can be passed to create\_model, and only the other entries can be passed to load\_entry.

**Returns**

The entry names.

### load\_entry

```python
def load_entry(self, entry_name: str) -> bytes
```

Reads the payload of a non-MXQ entry in the package into memory.

The whole payload is read at once and verified against the checksum stored in the package. This is intended for small entries such as a manifest. MXQ entries are rejected; use create\_model for them.

**Parameters**

- `entry_name` *\[in\]* — The name of the entry in the package (e.g. "manifest.json").

**Returns**

The entry payload.
