Concatenate function arguments with "AND" string if they're not None. Basically, if the function parameter is None, I ignore it, else I concatenate all arguments like arg1:arg1_value AND arg2:arg2_value AND arg4:arg4_value considering arg3==None when the function got called.

def _get_query_string_for_get_config(self, host, app_name, instance, config_source, config_name):
    query_string = ""
    if host is not None:
        query_string += "host:{} AND ".format(host)
    if app_name is not None:
        query_string += "app_name:{} AND ".format(app_name)
    if instance is not None:
        query_string += "instance:{} AND ".format(instance)
    if config_source is not None:
        query_string += "config_source:{} AND ".format(config_source)
    if config_name is not None:
        query_string += "config_name:{}".format(config_name)

    return query_string
Concatenating strings with a common connector (such as ' AND ' here) is most idiomatically done using join. So the idea should be to:

return ' AND '.join(&lt;some list with the right `text:value` formatting&gt;)


The easiest way to get such list should be to pair the text part and the associated value using zip and then use a list comprehension to filter out undesired variables:

parameters = zip(
    ('host', 'app_name', 'instance', 'config_source', 'config_name'),
    (host, app_name, instance, config_source, config_name)
)
query = ['{}:{}'.format(text, value) for text, value in parameters if value is not None]
return ' AND '.join(query)


You can also simplify a bit by turning the list-comprehension into a generator expression and feeding it directly to join.

Lastly, the self parameter suggest that you are using this as a method of a class. But since you are not using self in the method, you should either make it a regular function or a saticmethod:

@staticmethod
def _get_query_string_for_get_config(host, app_name, instance, config_source, config_name):
    parameters = zip(
        ('host', 'app_name', 'instance', 'config_source', 'config_name'),
        (host, app_name, instance, config_source, config_name)
    )
    return ' AND '.join(
        '{}:{}'.format(text, value)
        for text, value in parameters
        if value is not None)