Home / Function/ to_key_val_list() — requests Function Reference

to_key_val_list() — requests Function Reference

Architecture documentation for the to_key_val_list() function in utils.py from the requests codebase.

Function python CoreAPI VerbHandlers calls 1 called by 3

Entity Profile

Dependency Diagram

graph TD
  1d5603b3_e7c9_dfae_a29a_d8c05ae35261["to_key_val_list()"]
  2c39b9da_e317_5e6c_bbac_8362bac2110c["utils.py"]
  1d5603b3_e7c9_dfae_a29a_d8c05ae35261 -->|defined in| 2c39b9da_e317_5e6c_bbac_8362bac2110c
  05aa4b39_ee11_5653_43fd_4e9fe439edad["_encode_params()"]
  05aa4b39_ee11_5653_43fd_4e9fe439edad -->|calls| 1d5603b3_e7c9_dfae_a29a_d8c05ae35261
  8078fe73_7320_a15b_369b_220683f56710["_encode_files()"]
  8078fe73_7320_a15b_369b_220683f56710 -->|calls| 1d5603b3_e7c9_dfae_a29a_d8c05ae35261
  dba9d4ef_b6f9_4932_f472_7c695f48234a["merge_setting()"]
  dba9d4ef_b6f9_4932_f472_7c695f48234a -->|calls| 1d5603b3_e7c9_dfae_a29a_d8c05ae35261
  342c3122_113c_32a4_2286_94935f7ac0a8["items()"]
  1d5603b3_e7c9_dfae_a29a_d8c05ae35261 -->|calls| 342c3122_113c_32a4_2286_94935f7ac0a8
  style 1d5603b3_e7c9_dfae_a29a_d8c05ae35261 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/requests/utils.py lines 333–359

def to_key_val_list(value):
    """Take an object and test to see if it can be represented as a
    dictionary. If it can be, return a list of tuples, e.g.,

    ::

        >>> to_key_val_list([('key', 'val')])
        [('key', 'val')]
        >>> to_key_val_list({'key': 'val'})
        [('key', 'val')]
        >>> to_key_val_list('string')
        Traceback (most recent call last):
        ...
        ValueError: cannot encode objects that are not 2-tuples

    :rtype: list
    """
    if value is None:
        return None

    if isinstance(value, (str, bytes, bool, int)):
        raise ValueError("cannot encode objects that are not 2-tuples")

    if isinstance(value, Mapping):
        value = value.items()

    return list(value)

Domain

Subdomains

Calls

Frequently Asked Questions

What does to_key_val_list() do?
to_key_val_list() is a function in the requests codebase, defined in src/requests/utils.py.
Where is to_key_val_list() defined?
to_key_val_list() is defined in src/requests/utils.py at line 333.
What does to_key_val_list() call?
to_key_val_list() calls 1 function(s): items.
What calls to_key_val_list()?
to_key_val_list() is called by 3 function(s): _encode_files, _encode_params, merge_setting.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free