Skip to content

Funcs

ph_from_json

ph_from_json(data)

Decode a Python dict using the Haystack JSON encoding defined here to a Project Haystack kind.

Example:

from phable import ph_from_json

data = {"equip": {"_kind": "marker"}}
ph_from_json(data)
# {"equip": Marker()}

Parameters:

Name Type Description Default
data dict[str, typing.Any]

A Python dict using the Haystack JSON encoding.

required

Returns:

Type Description
phable.kinds.PhKind

A Project Haystack kind.

Source code in src/phable/utils.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
def ph_from_json(data: dict[str, Any]) -> PhKind:
    """Decode a Python dict using the Haystack JSON encoding defined
    [here](https://project-haystack.org/doc/docHaystack/Json) to a Project Haystack
    kind.

    **Example:**
    ```python
    from phable import ph_from_json

    data = {"equip": {"_kind": "marker"}}
    ph_from_json(data)
    # {"equip": Marker()}
    ```

    Parameters:
        data: A Python dict using the Haystack JSON encoding.

    Returns:
        A Project Haystack kind.
    """
    return _JSON_CODEC.from_dict(data)

ph_to_json

ph_to_json(data)

Encode a Project Haystack kind to a Python dict using the Haystack JSON encoding defined here.

Example:

from phable import Marker, ph_to_json

data = {"equip": Marker()}
ph_to_json(data)
# {"equip": {"_kind": "marker"}}

Parameters:

Name Type Description Default
data phable.kinds.PhKind

A Project Haystack kind to encode.

required

Returns:

Type Description
dict[str, typing.Any]

A Python dict representation of the Haystack JSON encoding.

Source code in src/phable/utils.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
def ph_to_json(data: PhKind) -> dict[str, Any]:
    """Encode a Project Haystack kind to a Python dict using the Haystack JSON encoding
    defined [here](https://project-haystack.org/doc/docHaystack/Json).

    **Example:**
    ```python
    from phable import Marker, ph_to_json

    data = {"equip": Marker()}
    ph_to_json(data)
    # {"equip": {"_kind": "marker"}}
    ```

    Parameters:
        data: A Project Haystack kind to encode.

    Returns:
        A Python dict representation of the Haystack JSON encoding.
    """
    return _JSON_CODEC.to_dict(data)

ph_from_zinc

ph_from_zinc(data)

Decode a Zinc string using the Haystack Zinc encoding defined here to a Project Haystack kind.

Example:

from phable import ph_from_zinc

ph_from_zinc('{equip}')
# {"equip": Marker()}

Parameters:

Name Type Description Default
data str

A Zinc string to decode.

required

Returns:

Type Description
phable.kinds.PhKind

A Project Haystack kind.

Source code in src/phable/utils.py
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
def ph_from_zinc(data: str) -> PhKind:
    """Decode a Zinc string using the Haystack Zinc encoding defined
    [here](https://project-haystack.org/doc/docHaystack/Zinc) to a Project Haystack
    kind.

    **Example:**
    ```python
    from phable import ph_from_zinc

    ph_from_zinc('{equip}')
    # {"equip": Marker()}
    ```

    Parameters:
        data: A Zinc string to decode.

    Returns:
        A Project Haystack kind.
    """
    return _ZINC_CODEC.from_str(data)

ph_to_zinc

ph_to_zinc(data)

Encode a Project Haystack kind to a Zinc string using the Haystack Zinc encoding defined here.

Example:

from phable import Marker, ph_to_zinc

data = {"equip": Marker()}
ph_to_zinc(data)
# '{equip}'

Parameters:

Name Type Description Default
data phable.kinds.PhKind

A Project Haystack kind to encode.

required

Returns:

Type Description
str

A Zinc string representation of the Project Haystack kind.

Source code in src/phable/utils.py
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
def ph_to_zinc(data: PhKind) -> str:
    """Encode a Project Haystack kind to a Zinc string using the Haystack Zinc encoding
    defined [here](https://project-haystack.org/doc/docHaystack/Zinc).

    **Example:**
    ```python
    from phable import Marker, ph_to_zinc

    data = {"equip": Marker()}
    ph_to_zinc(data)
    # '{equip}'
    ```

    Parameters:
        data: A Project Haystack kind to encode.

    Returns:
        A Zinc string representation of the Project Haystack kind.
    """
    return _ZINC_CODEC.to_str(data)