---
title: "Slice Loaders"
url: https://docs.zeroc.com/ice/3.8/slice/user-defined-types/classes/slice-loaders
language: python
docs_index: https://docs.zeroc.com/llms.txt
---

> For an index of every page, see [llms.txt](https://docs.zeroc.com/llms.txt).

# Slice Loaders

Programming language: Python. Other languages: [C++](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/classes/slice-loaders/cpp.md), [C#](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/classes/slice-loaders/csharp.md), [Java](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/classes/slice-loaders/java.md), [JavaScript](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/classes/slice-loaders/js.md), [MATLAB](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/classes/slice-loaders/matlab.md), [PHP](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/classes/slice-loaders/php.md), [Ruby](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/classes/slice-loaders/ruby.md), [Swift](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/classes/slice-loaders/swift.md).

When Ice unmarshals a Slice-defined class or exception, it starts by locating the mapped class and creating an instance of this class.

The abstraction that drives this locate and create process is called the Slice loader. Each communicator has a default Slice loader, implemented by Ice, that locates the generated class for a Slice type ID.

## Custom Slice Loaders

You can install your own custom Slice loader on a communicator to create instances of your own classes, typically classes derived from the generated classes, during unmarshaling. The communicator calls your Slice loader first, and falls back on its default Slice loader when your Slice loader doesn't create an instance.

A custom Slice loader is a callable that takes a type ID and returns a new instance. You install it by setting the `sliceLoader` field of [InitializationData](https://code.zeroc.com/ice/3.8/api/python/Ice.InitializationData.html):

```py
def node_loader(typeId: str) -> Ice.Value | None:
    return MyNode() if typeId == "::Demo::Node" else None

initData = Ice.InitializationData(sliceLoader=node_loader)
with Ice.Communicator(initData=initData) as communicator:
    ...
```

Ice for Python calls your Slice loader only for Slice classes: for a Slice exception, it always creates an instance of the class generated by `slice2py`.

## See Also

- [Type IDs](https://docs.zeroc.com/ice/3.8/slice/type-ids.md)
