tooluniverse.openfda_tool module

class tooluniverse.openfda_tool.BaseTool(tool_config)[source][source]

Bases: object

__init__(tool_config)[source][source]
classmethod get_default_config_file()[source][source]

Get the path to the default configuration file for this tool type.

This method uses a robust path resolution strategy that works across different installation scenarios:

  1. Installed packages: Uses importlib.resources for proper package resource access

  2. Development mode: Falls back to file-based path resolution

  3. Legacy Python: Handles importlib.resources and importlib_resources

Override this method in subclasses to specify a custom defaults file.

Returns:

Path or resource object pointing to the defaults file

classmethod load_defaults_from_file()[source][source]

Load defaults from the configuration file

run(arguments=None)[source][source]

Execute the tool.

The default BaseTool implementation accepts an optional arguments mapping to align with most concrete tool implementations which expect a dictionary of inputs.

check_function_call(function_call_json)[source][source]
get_required_parameters()[source][source]

Retrieve required parameters from the endpoint definition. Returns: list: List of required parameters for the given endpoint.

tooluniverse.openfda_tool.register_tool(tool_type_name=None, config=None)[source][source]

Decorator to automatically register tool classes and their configs.

Usage:

@register_tool(‘CustomToolName’, config={…}) class MyTool:

pass

tooluniverse.openfda_tool.check_keys_present(api_capabilities_dict, keys)[source][source]
tooluniverse.openfda_tool.extract_nested_fields(records, fields, keywords=None)[source][source]

Recursively extracts nested fields from a list of dictionaries.

Parameters:
  • records – List of dictionaries from which to extract fields

  • fields – List of nested fields to extract, each specified with dot notation (e.g., ‘openfda.brand_name’)

Returns:

List of dictionaries containing only the specified fields

tooluniverse.openfda_tool.map_properties_to_openfda_fields(arguments, search_fields)[source][source]

Maps the provided arguments to the corresponding openFDA fields based on the search_fields mapping.

Parameters:
  • arguments – The input arguments containing property names and values.

  • search_fields – The mapping of property names to openFDA fields.

Returns:

A dictionary with openFDA fields and corresponding values.

tooluniverse.openfda_tool.extract_sentences_with_keywords(text_list, keywords)[source][source]

Extracts sentences containing any of the specified keywords from the text.

Parameters: - text (str): The input text from which to extract sentences. - keywords (list): A list of keywords to search for in the text.

Returns: - list: A list of sentences containing any of the keywords.

tooluniverse.openfda_tool.search_openfda(params=None, endpoint_url=None, api_key=None, sort=None, limit=5, skip=None, count=None, exists=None, return_fields=None, exist_option='OR', search_keyword_option='AND', keywords_filter=True)[source][source]
class tooluniverse.openfda_tool.FDATool(tool_config, endpoint_url, api_key=None)[source][source]

Bases: BaseTool

__init__(tool_config, endpoint_url, api_key=None)[source][source]
run(arguments)[source][source]

Execute the tool.

The default BaseTool implementation accepts an optional arguments mapping to align with most concrete tool implementations which expect a dictionary of inputs.

class tooluniverse.openfda_tool.FDADrugLabelTool(tool_config, api_key=None)[source][source]

Bases: FDATool

__init__(tool_config, api_key=None)[source][source]
class tooluniverse.openfda_tool.FDADrugLabelSearchTool(tool_config=None, api_key=None)[source][source]

Bases: FDATool

__init__(tool_config=None, api_key=None)[source][source]
run(arguments)[source][source]

Execute the tool.

The default BaseTool implementation accepts an optional arguments mapping to align with most concrete tool implementations which expect a dictionary of inputs.

class tooluniverse.openfda_tool.FDADrugLabelSearchIDTool(tool_config=None, api_key=None)[source][source]

Bases: FDATool

__init__(tool_config=None, api_key=None)[source][source]
run(arguments)[source][source]

Execute the tool.

The default BaseTool implementation accepts an optional arguments mapping to align with most concrete tool implementations which expect a dictionary of inputs.

class tooluniverse.openfda_tool.FDADrugLabelGetDrugGenericNameTool(tool_config=None, api_key=None)[source][source]

Bases: FDADrugLabelTool

__init__(tool_config=None, api_key=None)[source][source]
run(arguments)[source][source]

Execute the tool.

The default BaseTool implementation accepts an optional arguments mapping to align with most concrete tool implementations which expect a dictionary of inputs.