def nsarg_completions(<EOL>completion_text: str,<EOL>entity_types: list,<EOL>bel_spec: BELSpec,<EOL>namespace: str,<EOL>species_id: str,<EOL>bel_fmt: str,<EOL>size: int,<EOL>):
minimal_nsarg_completion_len = <NUM_LIT:1><EOL>species = [species_id]<EOL>namespaces = [namespace]<EOL>replace_list = []<EOL>if len(completion_text) >= minimal_nsarg_completion_len:<EOL><INDENT>url = f'<STR_LIT>'<EOL>params = {<EOL>"<STR_LIT:size>": size,<EOL>"<STR_LIT>": entity_types,<EOL>"<STR_LIT>": namespaces,<EOL>"<STR_LIT>": species,<EOL>}<EOL>r = get_url(url, params=params)<EOL>if r.status_code == <NUM_LIT:200>:<EOL><INDENT>ns_completions = r.json()<EOL><DEDENT>else:<EOL><INDENT>log.error(f"<STR_LIT>")<EOL>ns_completions = {}<EOL><DEDENT>for complete in ns_completions.get("<STR_LIT>", []):<EOL><INDENT>replace_list.append(<EOL>{<EOL>"<STR_LIT>": complete["<STR_LIT:id>"],<EOL>"<STR_LIT:label>": f"<STR_LIT>",<EOL>"<STR_LIT>": complete["<STR_LIT>"][-<NUM_LIT:1>],<EOL>"<STR_LIT:type>": "<STR_LIT>",<EOL>}<EOL>)<EOL><DEDENT><DEDENT>for entity_type in entity_types:<EOL><INDENT>default_namespace = bel_spec["<STR_LIT>"].get(entity_type, [])<EOL>if default_namespace:<EOL><INDENT>for obj in default_namespace["<STR_LIT:info>"]:<EOL><INDENT>replacement = None<EOL>if bel_fmt == "<STR_LIT>" and re.match(<EOL>completion_text, obj["<STR_LIT:name>"], re.IGNORECASE<EOL>):<EOL><INDENT>replacement = obj["<STR_LIT:name>"]<EOL><DEDENT>elif bel_fmt in ["<STR_LIT>", "<STR_LIT>"] and re.match(<EOL>completion_text, obj["<STR_LIT>"], re.IGNORECASE<EOL>):<EOL><INDENT>replacement = obj["<STR_LIT>"]<EOL><DEDENT>if replacement:<EOL><INDENT>highlight = replacement.replace(<EOL>completion_text, f"<STR_LIT>"<EOL>)<EOL>replace_list.insert(<EOL><NUM_LIT:0>,<EOL>{<EOL>"<STR_LIT>": replacement,<EOL>"<STR_LIT:label>": replacement,<EOL>"<STR_LIT>": highlight,<EOL>"<STR_LIT:type>": "<STR_LIT>",<EOL>},<EOL>)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return replace_list[:size]<EOL>
Namespace completions

    Args:
        completion_text
        entity_types: used to filter namespace search results
        bel_spec: used to search default namespaces
        namespace: used to filter namespace search results
        species_id: used to filter namespace search results
        bel_fmt: used to select full name or abbrev for default namespaces
        size: how many completions to return

    Results:
        list of replacement text objects