# Chalk Python SDK Reference: Data Structure Functions
source: https://docs.chalk.ai/api-docs#section-data-structure-functions

## `map_dict(d, key, default)`
source: https://docs.chalk.ai/api-docs#map_dict

Map a key to a value in a dictionary.

**Parameters**

- `d`: `dict[KeyType, ValueType]`
  The dictionary to map the key to a value in.
- `key`: `Underscore`
  The key to look up in the dictionary.
- `default`: `ValueType | None`
  The default value to return if the key is not found in the dictionary.

**Examples**

```python
import chalk.functions as F
from chalk.features import _, features
@features
class Transaction:
   id: int
   merchant: str
   merchant_risk_score: float = F.map_dict(
       {"Amazon": 0.1, "Walmart": 0.08},
       _.merchant,
       default=0.,
   )
```

## `map_get(mapping, key)`
source: https://docs.chalk.ai/api-docs#map_get

Get the value for a key in a mapping.

**Parameters**

- `mapping`: `Mapping[KeyType, ValueType]`
  The mapping to get the value from.
- `key`: `Any`
  The key to get the value for.

**Examples**

```python
import chalk.functions as F
from chalk.features import _, features
@features
class Transaction:
   id: int
   merchant: str
   merchant_risk_score: float = F.map_get(
       {"Amazon": 0.1, "Walmart": 0.08},
       _.merchant,
   )
```

## `proto_deserialize(body, message)`
source: https://docs.chalk.ai/api-docs#proto_deserialize

Deserialize a proto message from a bytes feature.

**Parameters**

- `body`: `Underscore | bytes`
  The bytes feature to deserialize.
- `message`: `Type[Message]`
  The proto message type to deserialize.

**Examples**

```python
import chalk.functions as F
from chalk.features import _, features
from protos.gen.v1.transaction_pb2 import GetTransactionResponse
@features
class Transaction:
   id: int
   transaction_response_bytes: bytes
   transaction_response: GetTransactionResponse = F.proto_deserialize(
       _.transaction_response_bytes,
       GetTransactionResponse,
   )
```

## `proto_serialize(mapping, message)`
source: https://docs.chalk.ai/api-docs#proto_serialize

Serialize a proto message from a mapping of field names to values.

**Parameters**

- `mapping`: `Mapping[str, Underscore | Any]`
  The mapping of names to features to serialize.
- `message`: `Type[Message]`
  The proto message to serialize.

**Examples**

```python
import chalk.functions as F
from chalk.features import _, features
from protos.gen.v1.transaction_pb2 import GetTransactionRequest
@features
class Transaction:
   id: int
   transaction_request: bytes = F.proto_serialize(
       {
           "id": _.id,
       },
       GetTransactionRequest,
   )
```

## `struct_pack(mapping)`
source: https://docs.chalk.ai/api-docs#struct_pack

Construct a struct from a mapping of field names to values.

**Parameters**

- `mapping`: `Mapping[str, Underscore | Any]`
  The mapping of names to features to construct the struct from.

**Examples**

```python
import dataclasses
import chalk.functions as F
from chalk.features import _, features
@dataclasses.dataclass
class TransactionInfo:
   id: int
   merchant: str
@features
class Transaction:
   id: int
   merchant: str
   transaction_info: TransactionInfo = F.struct_pack({
       "id": _.id,
       "merchant": _.merchant,
   })
```
