Package: lexisnexisapi
Metabase.py Documentation1. IntroductionOverviewThemetabase.pymodule provides a Python interface to interact with the Metabase API. It allows you to perform searches and retrieve articles using the Metabase API. The module facilitates the creation of Python objects representing the API response, making it easy to work with the data.AuthorsRobert CuffneyOzgur AycanCS Integration Consultants @ LexisNexisVersionCurrent version: 3.0.3.122. InstallationDependenciesTo use themetabase.pymodule, you need the following dependencies:requestsjsonpandasdatetimelexisnexisapiInstallationYou can install the required dependencies using pip:pipinstallrequestspandaslexisnexisapi3. UsageImporting the ModuleTo use themetabase.pymodule in your Python script, import it as follows:fromlexisnexisapiimportmetabaseSearch ClassTheSearchclass is the main interface to perform searches and retrieve articles from Metabase. It has the following attributes and methods:Attributes:parameters: A dictionary of Metabase search parameters.articles: A list containing the articles retrieved from the Metabase API response.totalResults: The total number of articles available in the search results.Methods:__init__(self, full_dataset=False, **kwargs): Initializes the Search object and performs the API request. Iffull_datasetis set toTrue, it retrieves all available articles by making multiple API calls.articles_dataframe(self, *args): Returns a Pandas DataFrame containing the articles' data. You can pass a list of desired fields (*args) to filter the DataFrame.create_file(self, file='articles.json'): Creates a JSON file with the articles retrieved from the search.set_parameters(self, p): Sets the Metabase search parameters based on the input dictionaryp.Streamline ClassTheStreamlineclass helps maximize Metabase search calls without exceeding the rate limit. It keeps track of the remaining API calls per minute and waits for a new minute if needed.Attributes:key: Metabase API key.start_minute: The starting minute when the Streamline object is instantiated.minute_limit: The maximum number of API calls allowed per minute based on the rate limit.calls_remaining: The remaining API calls within the current minute.Methods:__init__(self, key): Initializes the Streamline object with the Metabase API key and fetches the rate limit information.track_calls(self): Updates the remaining API calls and waits for a new minute if the limit is reached.restart(self): Restarts the Streamline object.wait_for_new_min(self): Pauses execution until a new minute starts.get_current_minute(self): Returns the current minute as an integer.Article ClassTheArticleclass represents an instance of a single article retrieved from Metabase. It sets each key from the article dictionary as an attribute of the class.Helper FunctionsThe module also provides some helper functions:http_request(p): Performs an HTTP request to the Metabase API with the given parameterspand returns the API response as a dictionary.rate_check(mbkey): Calls the Metabase rate limit API and returns the results as a list of dictionaries.set_Metabase_Search_Key(v): Sets the Metabase search key in the credentials.get_time(): Returns the current minute as an integer.4. ExamplesBasic Search Examplefromlexisnexisapiimportmetabase# Set the Metabase search key (optional, you can set it in the parameters directly)metabase.set_mb_search_key("your_metabase_key")# Perform a basic searchsearch=metabase.Search(query="your_query_here",limit=100)# Get the DataFrame of articlesdf=search.articles_dataframe("title","author","published_date")print(df.head())Full Dataset Search Examplefromlexisnexisapiimportmetabase# Set the Metabase search key (optional, you can set it in the parameters directly)metabase.set_mb_search_key("your_metabase_key")# Perform a full dataset searchsearch=metabase.Search(full_dataset=True,query="your_query_here")# Create a JSON file with all the articlessearch.create_file("articles_full.json")Article Instance Examplefromlexisnexisapiimportmetabase# Set the Metabase search key (optional, you can set it in the parameters directly)metabase.set_mb_search_key("your_metabase_key")# Perform a search and get an article instancesearch=metabase.Search(query="your_query_here",limit=1)article_instance=metabase.Article(search.articles[0])# Access attributes of the article instanceprint(article_instance.title)print(article_instance.author)print(article_instance.published_date)Index Terms Examplefromlexisnexisapiimportmetabase# Set the Metabase search key (optional, you can set it in the parameters directly)metabase.set_mb_search_key("your_metabase_key")# Perform a searchsearch=metabase.Search(query="your_query_here",limit=100)# Get the DataFrame of index termsindex_terms_df=metabase.indexTerms(search,"economy","politics","technology")print(index_terms_df.head())Please note that you should replaceyour_metabase_keyandyour_query_herewith your actual Metabase API key and desired search query, respectively, in the examples.