# @spl.map

Toolkits > com.ibm.streamsx.topology 1.15.9 > com.ibm.streamsx.topology.python > Creating SPL Operators from Python code > @spl.map

Decorator to create a stateful or stateless SPL map operator from a Python callable class or function. A map operator has a single input port and a single output port. For each tuple arriving on the input port zero or more SPL tuples are submitted based upon the value returned from the invocation of the Python callable that is passed the SPL tuple.

## Decorated callable class

When a Python callable class is decorated with `@spl.map` a stateful SPL map operator is created.

    @spl.map
    class AddSeq:
        "Add a sequence number as the last attribute."
        def __init__(self):
            self.seq = 0

        def __call__(self, *tuple):
            id = self.seq
            self.seq += 1
            return tuple + (id,)

When the SPL operator is initialized `__init__` is called to create an instance of the class. Subsequent tuple arrivals result in calls to the `__call__` function of this instance.

For each tuple arriving at the input port `__call__` is called and its return value is used to submit zero or more tuples on the output port.

If the class has instance fields then they are the state of the operator and are private to each invocation of the operator and maintained across calls to its `__call__` function.

A map operator is punctuation perserving.

## Decorated function

When a Python function is decorated with `@spl.map` a stateless SPL map operator is created.

    @spl.map
    def Noop(*tuple):
        "Pass the tuple along without any change."
        return tuple

For each tuple arriving at the input port the decorated function is called and its return value is used to submit zero or more tuples on the output port.

## SPL output tuples

When a Python value does not provide values for all the SPL attributes of the output port, then any unset values are:

- set to the value of the matching attribute in the input port if it exists (attributes match by SPL type and name)
- otherwise it is set to the default value for the type, zero, empty string or empty collection.