Skip to main content

Metabase.py Documentation

1. Introduction

Overview

The metabase.py module 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.

Authors

  • Robert Cuffney
  • Ozgur Aycan
  • CS Integration Consultants @ LexisNexis

Version

Current version: 3.0.3.12

2. Installation

Dependencies

To use the metabase.py module, you need the following dependencies:

  • requests
  • json
  • pandas
  • datetime
  • lexisnexisapi

Installation

You can install the required dependencies using pip:

pip install requests pandas lexisnexisapi

3. Usage

Importing the Module

To use the metabase.py module in your Python script, import it as follows:

from lexisnexisapi import metabase

Search Class

The Search class 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. If full_dataset is set to True, 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 dictionary p.

Streamline Class

The Streamline class 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 Class

The Article class 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 Functions

The module also provides some helper functions:

  • http_request(p): Performs an HTTP request to the Metabase API with the given parameters p and 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. Examples

Basic Search Example

from lexisnexisapi import metabase

# 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 search
search = metabase.Search(query="your_query_here", limit=100)

# Get the DataFrame of articles
df = search.articles_dataframe("title", "author", "published_date")
print(df.head())

Full Dataset Search Example

from lexisnexisapi import metabase

# 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 search
search = metabase.Search(full_dataset=True, query="your_query_here")

# Create a JSON file with all the articles
search.create_file("articles_full.json")

Article Instance Example

from lexisnexisapi  import metabase

# 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 instance
search = metabase.Search(query="your_query_here", limit=1)
article_instance = metabase.Article(search.articles[0])

# Access attributes of the article instance
print(article_instance.title)
print(article_instance.author)
print(article_instance.published_date)

Index Terms Example

from lexisnexisapi import metabase

# 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
search = metabase.Search(query="your_query_here", limit=100)

# Get the DataFrame of index terms
index_terms_df = metabase.indexTerms(search, "economy", "politics", "technology")
print(index_terms_df.head())

Please note that you should replace your_metabase_key and your_query_here with your actual Metabase API key and desired search query, respectively, in the examples.

Release files for lexisnexisapi 3.0.3.13

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lexisnexisapi 3.0.3.13
File Size Uploaded
lexisnexisapi-3.0.3.13.tar.gz 10.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lexisnexisapi 3.0.3.13
File Interpreter ABI Platform
lexisnexisapi-3.0.3.13-py3-none-any.whl Python 3 none any Details

Total release size: 20.2 kB

Release files / lexisnexisapi-3.0.3.13.tar.gz

Download URL lexisnexisapi-3.0.3.13.tar.gz
Size 10.4 kB
Tags Source
SHA-256 checksum
How to use checksums
6b8ba21481b39f99858858652465cb4045e3affda7dff03a0770bfe3e365f2aa
BLAKE2b-256 checksum
How to use checksums
3ab08abcfbc220978589ae36c2942a6873b8e969e6421a3702be76816991b7a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.8

Release files / lexisnexisapi-3.0.3.13-py3-none-any.whl

Download URL lexisnexisapi-3.0.3.13-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d1b8a83902e0004b80235824fa6aea01429b9ccf20e66bed6e36a0060d8af0f2
BLAKE2b-256 checksum
How to use checksums
8d309c2a43fb75667291ffd269e56081cab351d7c7ca82277b84755760a73c73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.8

Release history Release notifications | RSS feed

This release

3.0.3.13 This release

2 release files

3.0.3

2 release files

3.0.2

2 release files

3.0.1

2 release files

3.0

2 release files

2.0.49

2 release files

2.0.48

2 release files

2.0.47

2 release files

2.0.46

2 release files

2.0.45

2 release files

2.0.44

2 release files

2.0.41

2 release files

2.0.40

2 release files

2.0.39

2 release files

2.0.38

2 release files

2.0.37

2 release files

2.0.36

2 release files

2.0.35

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page