Documentation
Main Module
It’s the interface module of the package. Developers will start interacting with the API/package using Medium Class object via different functions provided in it.
- class medium_api.medium.Medium(rapidapi_key: str, base_url: str = 'medium2.p.rapidapi.com', endpoint_prefix='', calls: int = 0)[source]
Bases:
object
Main Medium API Class to access everything
Typical usage example:
from medium_api import Medium
medium = Medium('YOUR_RAPIDAPI_KEY')
- Parameters:
rapidapi_key (str) –
A secret alphanumeric string value. To get your RapidAPI key, please go to the following URL, register an account and subscribe to Medium API (by Nishu Jain).
https://rapidapi.com/nishujain199719-vgIfuFHZxVZ/api/medium2
base_url (str, optional) – It’s the base URL of the API that is used by all the other endpoints. Currently, it is set to the RapidAPI’s domain (medium2.p.rapidapi.com). May change in the future according to where it’s listed.
calls (int, optional) –
It’s an integer value for keeping track of all the API calls made by the Medium Class Object. Initially, it is set to 0. At the end of program, you can see the number of calls like this:
print(medium.calls)
- Returns:
A Medium Class Object for the given RAPIDAPI_KEY. It can be used to access all the other functions such as: user, article, publication, topfeeds, top_writers, etc …
- Return type:
Note
See https://docs.rapidapi.com/docs/keys to learn more about RapidAPI keys.
- user(username: str | None = None, user_id: str | None = None, save_info: bool = True)[source]
For getting the Medium User Object
Typical usage example:
nishu = medium.user(username="nishu-jain")
- Parameters:
username (str, optional) –
It’s your unique Medium username that you can find in the subdomain or at the end of the profile page URL as shown below.
username
.medium.commedium.com/@
username
It’s optional only if you’ve already provided the user_id.
user_id (str, optional) – It’s your unique alphanumeric Medium ID that cannot be changed. The User object is initialized using this only. It’s optional only if you’ve already provided the username.
save_info (bool, optional) – If False, creates an empty User object which needs to be filled using
user.save_info()
method later. (Default is True)
- Returns:
Medium API’s User Object (medium_api._user.User) that can be used to access all the properties and methods associated to the given Medium user.
- Return type:
Note
You have to provide either username or user_id to get the User object. You cannot omit both.
- article(article_id: str, save_info: bool = True)[source]
For getting the Medium Article Object
Typical usage example:
article = medium.article(article_id = "562c5821b5f0")
- Parameters:
article_id (str) –
It’s the unique hash at the end of every Medium Article. You can see it at the end of URL as shown below:
save_info (bool, optional) – If False, creates an empty Article object which needs to be filled using
article.save_info()
method later. (Default is True)
- Returns:
Medium API Article Object (medium_api._article.Article) that can be used to access all the properties and methods related to a Medium Article.
- Return type:
- list(list_id: str, save_info: bool = True)[source]
For getting the Medium List Object
Typical usage example:
medium_list = medium.list(list_id = "38f9e0f9bea6")
- Parameters:
list_id (str) –
It’s the unique hash at the end of every Medium List URL. You can see it at the end of URL as shown below:
save_info (bool, optional) – If False, creates an empty Medium List object which needs to be filled using
medium_list.save_info()
method later. (Default is True)
- Returns:
Medium API Medium List Object (medium_api._medium_list.MediumList) that can be used to access all the properties and methods related to a Medium List.
- Return type:
- publication(publication_slug: str | None = None, publication_id: str | None = None, save_info: bool = True)[source]
For getting the Medium Publication Object
Typical usage example:
publication = medium.publication(publication_slug = "towards-artificial-intelligence")
publication = medium.publication(publication_id = "98111c9905da")
- Parameters:
publication_slug (str, optional) – It’s a lowercased hyphen-separated unique string alloted to each Medium Publication. It’s optional only if you’ve already provided the publication_id.
publication_id (str, optional) – It’s the unique hash id of a Medium Publication. It’s optional only if you’ve already provided the publication_slug.
save_info (bool, optional) – If False, creates an empty Publication object which needs to be filled using
publication.save_info()
method later. (Default is True)
- Returns:
Medium API Publication Object (medium_api._publication.Publication) that can be used to access all the properties and methods related to a Medium Publication.
- Return type:
Note
You have to provide either publication_slug or publication_id to get the Publication object. You cannot omit both.
- top_writers(topic_slug: str, count: int = 100)[source]
For getting the Medium’s TopWriters Object
Typical usage example:
top_writers = medium.top_writers(topic_slug = "artificial-intelligence")
- Parameters:
topic_slug (str) – It’s a string (smallcase, hyphen-separated) which specifies a category/niche as classified by the Medium Platform.
count (int) – Number of Top writers you want to fetch (less than 250).
- Returns:
Medium API TopWriters Object (medium_api._top_writers.TopWriters) that can be used to access all the properties and methods related to Medium’s Top Writers for the give topic_slug.
- Return type:
- latestposts(topic_slug: str)[source]
For getting the Medium’s LatestPosts Object
Typical usage example:
latestposts = medium.latestposts(topic_slug = "artificial-intelligence")
- Parameters:
topic_slug (str) – It’s a string (smallcase, hyphen-separated) which specifies a category/niche as classified by the Medium Platform.
- Returns:
Medium API LatestPosts Object (medium_api._latestposts.LatestPosts) that can be used to access all the properties and methods related to Medium’s LatestPosts within the given topic.
- Return type:
- topfeeds(tag: str, mode: str)[source]
For getting the Medium’s TopFeeds Object
Typical usage example:
topfeeds = medium.topfeeds(tag="blockchain", mode="new")
- Parameters:
tag (str) – It’s a string (smallcase, hyphen-separated) which specifies a category/niche as classified by the Medium Platform.
mode (str) –
There are 6 modes as follows:
hot
: For getting trending articlesnew
: For getting latest articlestop_year
: For getting best articles of the yeartop_month
: For getting best articles of the monthtop_week
: For getting best articles of the weektop_all_time
: For getting best article of all time
- Returns:
Medium API TopFeeds Object (medium_api._topfeeds.TopFeeds) that can be used to access all the properties and methods, for given tag and mode.
- Return type:
- recommended_feed(tag: str, count: int = 25)[source]
For getting the Medium’s RecommendedFeed Object
Typical usage example:
recommended_feed = medium.recommended_feed(tag="blockchain", count=100)
- Parameters:
tag (str) – It’s a string (smallcase, hyphen-separated) which specifies a category/niche as classified by the Medium Platform.
count (int) – Number of articles you want to fetch from recommended feed (Should be less than 500).
- Returns:
Medium API RecommendedFeed Object (medium_api._recommended_feed.RecommendedFeed) that can be used to access all the properties and methods, for given tag.
- Return type:
For getting the list of related tags
Typical usage example:
related_tags = medium.related_tag(given_tag="blockchain")
- Parameters:
given_tag (str) – It’s a string (lowercase, hyphen-separated) which specifies a category/niche as classified by the Medium Platform.
- Returns:
List of Related Tags (strings).
- Return type:
list[str]
- tag_info(tag: str)[source]
To get the tag-related information
Typical usage example:
blockchain_tag = medium.tag_info(given_tag="blockchain")
- Parameters:
tag (str) – It’s a string (lowercase, hyphen-separated) which specifies a category/niche as classified by the Medium Platform.
- Returns:
Contains tag-related information
- Return type:
dict
- recommended_users(tag: str)[source]
For getting the Medium’s RecommendedUsers Object
Typical usage example:
recommended_users = medium.recommended_users(tag="data-science")
- Parameters:
tag (str) – It’s a string (smallcase, hyphen-separated) which specifies a category/niche as classified by the Medium Platform.
- Returns:
Medium API RecommendedUsers Object (medium_api._recommended_users.RecommendedUsers) that can be used to access all the properties and methods, for given tag.
- Return type:
- recommended_lists(tag: str)[source]
For getting the Medium’s RecommendedLists Object
Typical usage example:
recommended_lists = medium.recommended_lists(tag="artificial-intelligence")
- Parameters:
tag (str) – It’s a string (smallcase, hyphen-separated) which specifies a category/niche as classified by the Medium Platform.
- Returns:
Medium API RecommendedLists Object (medium_api._recommended_lists.RecommendedLists) that can be used to access all the properties and methods, for given tag.
- Return type:
- archived_articles(tag: str, count: int = 20, year: str = '', month: str = '', next: str = '')[source]
For getting the Medium’s ArchivedArticles Object
Typical usage example:
archived_articles = medium.archived_articles(tag="artificial-intelligence", count=100)
- Parameters:
tag (str) – It’s a string (smallcase, hyphen-separated) which specifies a category/niche as classified by the Medium Platform.
count (int) – Number of archived articles you want to fetch.
year (str, optional) – It’s the year for which you want to fetch the archived articles. If not provided, it fetches articles for ‘all_years’.
month (str, optional) – It’s the month for which you want to fetch the archived articles. If not provided, it fetches the articles for ‘all_months’.
next (str, optional) – It’s the hash id of the last article fetched in the previous call. If provided, it fetches the next set of articles.
- Returns:
Medium API ArchivedArticles Object (medium_api._archived_articles.ArchivedArticles) that can be used to access all the properties and methods, for given tag.
- Return type:
- root_tags()[source]
To get the list of root tags
Typical usage example:
root_tags = medium.root_tags()
- Returns:
List of Root Tags (strings).
- Return type:
list[str]
- search_articles(query: str, save_info: bool = False)[source]
To get the list of Articles for the given search query, from the Medium Platform.
Typical usage example:
ai_articles = medium.search_articles(query = "artificial intelligence")
- Parameters:
query (str) – It’s the search query to get results from Medium Platform.
save_info (bool, optional) – If True, the function will fetch article-related info for all the articles in the search result, using multi-threading. Else, the returned list will contain the empty Article objects. Default is False.
- Returns:
List of Article objects from the search results.
- Return type:
list[Article]
Note
The resultant list will contain 1000 Article objects at max.
Warning
OveruseWarning: Don’t set
save_info = True
unless you have enough API calls in your subscribed plan. You might either exhaust your current plan or incur overage.
- search_publications(query: str, save_info: bool = False)[source]
To get the list of Publications for the given search query, from the Medium Platform.
Typical usage example:
mental_health_pubs = medium.search_publications(query = "mental health")
- Parameters:
query (str) – It’s the search query to get results from Medium Platform.
save_info (bool, optional) – If True, the function will fetch publication-related info for all the publications in the search result, using multi-threading. Else, the returned list will contain the empty Publication objects. Default is False.
- Returns:
List of Publication objects from the search results.
- Return type:
list[Publication]
Note
The resultant list will contain 1000 Publication objects at max.
Warning
OveruseWarning: Don’t set
save_info = True
unless you have enough API calls in your subscribed plan. You might either exhaust your current plan or incur overage.
- search_users(query: str, save_info: bool = False)[source]
To get the list of Users for the given search query, from the Medium Platform.
Typical usage example:
data_engineers = medium.search_users(query = "data engineer")
- Parameters:
query (str) – It’s the search query to get results from Medium Platform.
save_info (bool, optional) – If True, the function will fetch user-related info for all the users in the search result, using multi-threading. Else, the returned list will contain the empty User objects. Default is False.
- Returns:
List of User objects from the search results.
- Return type:
list[User]
Note
The resultant list will contain 1000 User objects at max.
Warning
OveruseWarning: Don’t set
save_info = True
unless you have enough API calls in your subscribed plan. You might either exhaust your current plan or incur overage.
- search_lists(query: str, save_info: bool = False)[source]
To get an array of MediumList objects for the given search query, from the Medium Platform.
Typical usage example:
startup_lists = medium.search_lists(query = "startup")
- Parameters:
query (str) – It’s the search query to get results from Medium Platform.
save_info (bool, optional) – If True, the function will fetch List-related info for all the Medium Lists in the search result, using multi-threading. Else, the returned array will contain the empty MediumList objects. Default is False.
- Returns:
Array of MediumList objects from the search results.
- Return type:
list[MediumList]
Note
The resultant list will contain 1000 MediumList objects at max.
Warning
OveruseWarning: Don’t set
save_info = True
unless you have enough API calls in your subscribed plan. You might either exhaust your current plan or incur overage.
- search_tags(query: str)[source]
To get the list of tags for the given search query, from the Medium Platform.
Typical usage example:
blockchain_tags = medium.search_tags(query = "blockchain")
- Parameters:
query (str) – It’s the search query to get results from Medium Platform.
- Returns:
List of lowercased, hyphen-separated strings of tags
- Return type:
list[str]
Note
The resultant list will contain 1000 tags at max.
- fetch_articles(articles: list, content: bool = False, markdown: bool = False, html: bool = False, html_fullpage: bool = True, html_style_file: str = 'https://mediumapi.com/styles/dark.css')[source]
To quickly fetch articles (info, content, markdown, html) using multithreading
Typical usage example:
medium.fetch_articles(latestposts.articles)
medium.fetch_articles(user.articles)
medium.fetch_articles(list_of_articles_obj)
- Parameters:
articles (list[Article]) – List of (empty) Article objects to fill information (and content) into it.
content (bool, optional) – Set it to True if you want to fetch the content of the article as well. Otherwise, default is False
markdown (bool, optional) – Set it to True if you want to fetch the markdown of the article as well. Otherwise, default is False
html (bool, optional) – Set it to True if you want to fetch the article in HTML format as well. Otherwise, default is False
html_fullpage (bool, optional) – Set it to False if you only want to fetch the HTML inside body tag of the article. Otherwise, default is True, which fetches the entire HTML of the article.
- Returns:
This method doesn’t return anything since it fills the values in the passed list of Article(s) objects itself.
- Return type:
None
- fetch_publications(publications: list)[source]
To quickly fetch publications’ info using multithreading
Typical usage example:
medium.fetch_publications(user.publications)
medium.fetch_publications(list_of_publications_obj)
- Parameters:
publications (list[Publication]) – List of (empty) Publications objects to fill information into it.
- Returns:
This method doesn’t return anything since it fills the values in the passed list of Publication(s) objects itself.
- Return type:
None
- fetch_lists(medium_lists: list)[source]
To quickly fetch Medium List related info using multithreading
Typical usage example:
medium.fetch_lists(user.lists)
medium.fetch_lists(arr_of_medium_list_objs)
- Parameters:
medium_lists (list[MediumList]) – An array of (empty) MediumList objects to fill information into it.
- Returns:
This method doesn’t return anything since it fills the values in the passed array of MediumList(s) objects itself.
- Return type:
None
- fetch_users(users: list)[source]
To quickly fetch users’ info using multithreading
Typical usage example:
medium.fetch_users(top_writers.users)
medium.fetch_users(list_of_users_obj)
- Parameters:
users (list[User]) – List of (empty) User objects to fill information into it.
- Returns:
This method doesn’t return anything since it fills the values into the passed list of User(s) objects itself.
- Return type:
None
- extract_article_id(article_url: str)[source]
To get article_id from the Article’s URL
Usage example:
article_id = medium.get_article_id("https://nishu-jain.medium.com/about-me-nishu-jain-562c5821b5f0")
- Parameters:
article_url (str) – URL as string type
- Returns:
Returns article_id as string for valid URL, else returns None.
- Return type:
str
Classes
User class
- class medium_api._user.User(user_id, get_resp, fetch_articles, fetch_users, fetch_publications, fetch_lists, save_info=False)[source]
User Class
With User object, you can use the following properties and methods:
user._id
user.info
user.article_ids
user.articles
user.top_article_ids
user.top_articles
user.following_ids
user.following
user.followers_ids
user.followers
user.all_followers_ids
user.all_followers
user.interests
user.articles_as_json
user.publication_ids
user.publications
user.list_ids
user.lists
user.books
user.save_info()
user.fetch_articles()
user.fetch_top_articles()
user.fetch_following()
user.fetch_followers()
user.fetch_all_followers()
user.fetch_publications()
user.fetch_lists()
Note
User class is NOT intended to be used directly by importing. See
medium_api.medium.Medium.user
.- property info
To get the user related information
- Returns:
A dictionary object containing fullname, username, followers, bio, twitter_username, image_url, etc …
- Return type:
dict
- property article_ids
To get a full list of article_ids
- Returns:
A list of article_ids (str) written by the user
- Return type:
list[str]
- property publication_ids
To get a list of publication_ids where user is either creator and/or editor
- Returns:
A list of publication_ids (strings)
- Return type:
list[str]
- property list_ids
To get an array of list_ids
- Returns:
An array of list_ids (str) by the user
- Return type:
list[str]
- property publications
To get a list of Publication Objects where the user is either creator and/or editor
- Returns:
A list of Publication objects
- Return type:
list[Publication]
- property lists
To get an array of MediumList Objects created by the user
- Returns:
A list of MediumList objects
- Return type:
list[MediumList]
- property top_article_ids
To get a list of top 10 article_ids
- Returns:
A list of article_ids (str) of the top 10 posts on the user’s profile. (Usually, in chronological order)
- Return type:
list[str]
- property interests
To get a list of tags that the user follows.
- Returns:
A list of tags (str) followed by the user.
- Return type:
list[str]
- property following_ids
To get a list of user_ids of user’s followings
- Returns:
A list of user_ids (str) of the user’s followings.
- Return type:
list[str]
- property publication_following_ids
To get a list of publications_ids that the give user is followings
- Returns:
A list of publication_ids (str)
- Return type:
list[str]
- property publication_following
To get a list of Publication objects that the give user is followings
- Returns:
A list of Publication objects
- Return type:
list[Publication]
- property followers_ids
To get a list of user_ids of user’s followers (length = 25)
- Returns:
A list of user_ids (str) of the user’s followers (length = 25).
- Return type:
list[str]
- property all_followers_ids
To get a list of user_ids of user’s followers (all). This may take some time if the user has a lot of followers.
- Returns:
A list of user_ids (str) of the user’s followers (all).
- Return type:
list[str]
- property following
To get a full list of following User objects
- Returns:
A list of User objects followed by the given user
- Return type:
list[User]
- property followers
To get a full list of followers User objects
- Returns:
A list of User objects of followers
- Return type:
list[User]
- property all_followers
To get a full list of followers User objects
- Returns:
A list of User objects of followers
- Return type:
list[User]
- property articles
To get a full list of user-written Article objects
- Returns:
A list of Article objects written by the user
- Return type:
list[Article]
- property top_articles
To get a list of top 10 articles
- Returns:
A list of Article objects of the top 10 posts on the user’s profile. (Usually, in chronological order)
- Return type:
list[Article]
- property articles_as_json
To get a list of JSON objects containing user info
- Returns:
A list of JSON objects containing information related to all the posts on the user’s profile.
- Return type:
list[dict]
- save_info()[source]
Saves the information related to the user
Note
Only after running
user.save_info()
you can use the following variables:user.fullname
user.username
user.followers_count
user.following_count
user.bio
user.twitter_username
user.is_writer_program_enrolled
user.is_suspended
user.has_list
user.is_book_author
user.allow_notes
user.medium_member_at
user.top_writer_in
user.image_url
user.tipping_link
user.publication_following_count
user.bg_image_url
user.logo_image_url
- fetch_articles(content=False, markdown=False, html=False, html_fullpage=True, html_style_file='https://mediumapi.com/styles/dark.css')[source]
To fetch all the user-written articles information and content
- Parameters:
content (bool, optional) – Set it to True if you want to fetch the textual content of the article as well. Otherwise, default is False.
markdown (bool, optional) – Set it to True if you want to fetch the markdown of the article as well. Otherwise, default is False
html (bool, optional) – Set it to True if you want to fetch the article in HTML format as well. Otherwise, default is False
html_fullpage (bool, optional) – Set it to False if you only want to fetch the HTML inside body tag of the article. Otherwise, default is True, which fetches the entire HTML of the article.
- Returns:
All the fetched information will be access via user.articles.
user.articles[0].title
user.articles[1].claps
- Return type:
None
- fetch_publications(admin_in=True, writer_in=True)[source]
To fetch all the publication-related information where the given user is either an admin (creator/editor) or a contributing writer.
- Returns:
All the fetched information will be access via user.publications.
user.publications['admin_in'][0].name
user.publications['writer_in'][1].followers
- Return type:
None
- fetch_top_articles(content=False, markdown=False, html=False, html_fullpage=True, html_style_file='https://mediumapi.com/styles/dark.css')[source]
To fetch top 10 user-written top articles information and content
- Parameters:
content (bool, optional) – Set it to True if you want to fetch the textual content of the article as well. Otherwise, default is False.
markdown (bool, optional) – Set it to True if you want to fetch the markdown of the article as well. Otherwise, default is False
html (bool, optional) – Set it to True if you want to fetch the article in HTML format as well. Otherwise, default is False
html_fullpage (bool, optional) – Set it to False if you only want to fetch the HTML inside body tag of the article. Otherwise, default is True, which fetches the entire HTML of the article.
- Returns:
All the fetched information will be access via user.top_articles.
user.top_articles[0].title
user.top_articles[1].claps
- Return type:
None
- fetch_following()[source]
To get user’s followings information
- Returns:
All the fetched information will be access via user.following
user.following[0].fullname
user.following[1].bio
- Return type:
None
- fetch_publication_following()[source]
To get information related to publications that the user is following
- Returns:
All the fetched information will be access via user.publication_following
user.publication_following[0].name
user.publication_following[1].followers
- Return type:
None
- fetch_followers()[source]
To get user’s followers information (first 25)
- Returns:
All the fetched information will be access via user.followers
user.followers[0].fullname
user.followers[1].bio
- Return type:
None
Article class
- class medium_api._article.Article(article_id, get_resp, fetch_articles, fetch_users, fetch_publications, fetch_lists, save_info=False)[source]
Article Class
With Article object, you can use the following properties and methods:
article._id
article.info
article.responses
article.fans_ids
article.fans
article.related_articles_ids
article.related_articles
article.is_self_published
article.content
article.markdown
article.html
article.json
article.save_info()
article.save_content()
article.save_markdown()
article.save_html()
article.fetch_responses()
article.fetch_fans()
article.fetch_related_articles()
Note
Article class is NOT intended to be used directly by importing. See
medium_api.medium.Medium.article
.- save_info()[source]
Saves the information related to the article
Note
Only after running
article.save_info()
you can use the following variables:article.title
article.subtitle
article.claps
article.author
article.url
article.unique_slug
article.published_at
article.publication_id
article.tags
article.topics
article.last_modified_at
article.reading_time
article.word_count
article.responses_count
article.voters
article.lang
article.is_series
article.is_locked
article.is_shortform
article.image_url
article.publication
article.top_highlight
- save_content()[source]
Saves the textual content of the article
Can be accessed later using
article.content
- Returns:
None
- save_markdown()[source]
Saves the markdown of the article
Can be accessed later using
article.markdown
- Returns:
None
- property info
To get the articles information
- Returns:
Returns a dictionary object containing title, subtitle, claps, voters, author, publication_id, word_count, etc … (excluding content)
- Return type:
dict
- property response_ids
To get the list of ids of responses (comments) on the article
- Returns:
Returns a list of response_ids.
- Return type:
list
- property responses
To get the list of responses (Article Objects)
- Returns:
Returns a list of Article Objects.
- Return type:
list[Article]
- fetch_responses(content=False)[source]
To fetch all the responses/comments information and textual content.
- Parameters:
content (bool, optional) – Set it to True if you want to fetch the textual content of the response as well. Otherwise, default is False.
- Returns:
All the fetched information will be access via article.responses.
article.responses[0].content
article.responses[1].claps
- Return type:
None
- property fans_ids
To get the list of user_ids of the people who clapped on the article (voters or fans)
- Returns:
Returns a list of user_ids.
- Return type:
list
- property fans
To get the list of Users who clapped on the article (voters/fans).
- Returns:
Returns a list of User Objects.
- Return type:
list[User]
To get the list of article_ids of the related posts.
- Returns:
Returns a list of article_ids.
- Return type:
list
To get the list of related articles (Article Objects)
- Returns:
Returns a list of Article Objects.
- Return type:
list[Article]
- property recommended_articles_ids
To get the list of article_ids of the recommended posts for the given article.
- Returns:
Returns a list of article_ids.
- Return type:
list
- property recommended_articles
To get the list of recommended articles (Article Objects)
- Returns:
Returns a list of Article Objects.
- Return type:
list[Article]
- property is_self_published
To check if the article is self-published or not
- Returns:
Returns True if article is self-published, else False if article is published under a Medium Publication.
- Return type:
bool
- property content
To get the textual content of the article
- Returns:
A single string containing kicker, title, subtitle, paragraphs, image captions, listicles, etc … within an article
- Return type:
str
- property markdown
To get the Markdown of the Medium Article
- Returns:
A single string containing kicker, title, subtitle, paragraphs, images, listicles, etc … within an article, in the markdown format
- Return type:
str
- property html
To get the Medium Article in plain HTML format
- Returns:
A single string containing the entire article in HTML format
- Return type:
str
- property assets
To get the URL of the assets present in the Medium Article such as images, embedded youtube videos, gisthub gists, hyperlinks (anchors), etc …
- Returns:
An ArticleAssets Class Object
- Return type:
ArticleAssets
- save_html(fullpage: bool = False, style_file: str = 'https://mediumapi.com/styles/dark.css')[source]
Saves the article in plain HTML format
- Parameters:
fullpage (bool, optional) – If ‘True’, saves full HTML page with head, body, title and meta tags. Else, saves HTML inside body only.
style_file (str, optional) – Name or URL to the CSS style file that can be included in the HTML output of the Article. Default is ‘https://mediumapi.com/styles/dark.css’ (Sample CSS)
- Returns:
None
- property json
To get the articles information in JSON format
- Returns:
Returns a JSON object containing article info, content, markdown and html if already fetched. Else, returns an empty object.
- Return type:
dict
- fetch_fans()[source]
To fetch user-related information of the people who clapped on the article (voters/fans), using multi-threading
- Returns:
All the fetched information will be access via article.fans.
article.fans[0].name
article.fans[2].twitter_username
article.fans[1].bio
- Return type:
None
To fetch all the related articles information and textual content, using multi-threading
- Parameters:
content (bool, optional) – Set it to True if you want to fetch the textual content of the related articles as well. Otherwise, default is False.
markdown (bool, optional) – Set it to True if you want to fetch the Markdown content of the related articles as well. Otherwise, default is False.
html (bool, optional) – Set it to True if you want to fetch the HTML content of the related articles as well. Otherwise, default is False.
html_fullpage (bool, optional) – Set it to True if you want to fetch the HTML content (with head, title, meta tags, etc…) of the related articles as well. Otherwise, default is True.
- Returns:
All the fetched information will be access via article.related_articles.
article.related_articles[0].content
article.related_articles[2].title
article.related_articles[1].claps
- Return type:
None
- fetch_recommended_articles(content=False, markdown=False, html=False, html_fullpage=True, html_style_file='https://mediumapi.com/styles/dark.css')[source]
To fetch all the recommended articles information and textual content, using multi-threading
- Parameters:
content (bool, optional) – Set it to True if you want to fetch the textual content of the recommended articles as well. Otherwise, default is False.
markdown (bool, optional) – Set it to True if you want to fetch the Markdown content of the related articles as well. Otherwise, default is False.
html (bool, optional) – Set it to True if you want to fetch the HTML content of the related articles as well. Otherwise, default is False.
html_fullpage (bool, optional) – Set it to True if you want to fetch the HTML content (with head, title, meta tags, etc…) of the related articles as well. Otherwise, default is True.
- Returns:
All the fetched information will be access via article.recommended_articles.
article.recommended_articles[0].content
article.recommended_articles[2].title
article.recommended_articles[1].claps
- Return type:
None
Publication class
- class medium_api._publication.Publication(publication_id, get_resp, fetch_articles, fetch_users, fetch_publications, fetch_lists, save_info=False)[source]
Publication Class
With Publication object, you can use the following properties and methods:
publication._id
publication.info
publication.articles
publication.save_info()
publication.fetch_articles()
Note
Publication class is NOT intended to be used directly by importing. See
medium_api.medium.Medium.publication
.- property info
To get the publication related information
- Returns:
A dictionary object containing name, slug, followers, description, tagline, url, twitter_username, tags, etc …
- Return type:
dict
- save_info()[source]
Saves the information related to the publication
Note
Only after running
publication.save_info()
you can use the following variables:publication.name
publication.description
publication.tagline
publication.followers
publication.slug
publication.tags
publication.domain
publication.creator
publication.editors
publication.twitter_username
publication.instagram_username
publication.facebook_pagename
- articles_from_ids(article_ids)[source]
A generic function to get Article Objects from article_ids (list).
- Parameters:
article_ids (list[str]) – List of
article_ids
(string)- Returns:
Returns a list of Article Objects.
- Return type:
list[Article]
- get_articles_between(_from=None, _to=None, content=False, markdown=False, html=False, html_fullpage=True, html_style_file='https://mediumapi.com/styles/dark.css')[source]
To get publication articles within a datetime range.
Example usage:
publication.get_articles_between(_from=datetime.now(), _to=datetime.now() - timedelta(days=15))
- Parameters:
_from (datetime.datetime) – Starting date of the interval
_to (datetime.datetime) – Ending date of the interval
content (bool, optional) – Set it to True if you want to fetch the textual content of the article as well. Otherwise, default is False.
markdown (bool, optional) – Set it to True if you want to fetch the markdown of the article as well. Otherwise, default is False
html (bool, optional) – Set it to True if you want to fetch the article in HTML format as well. Otherwise, default is False
html_fullpage (bool, optional) – Set it to False if you only want to fetch the HTML inside body tag of the article. Otherwise, default is True, which fetches the entire HTML of the article.
- Returns:
Returns a list of Article Objects (publication articles).
- Return type:
list[Article]
Note
If the
_to
parameter is not provided, then the function will return recent 25 articles from the given date (in_from
parameter)If the
_from
parameter is not provided, then the function will take current datetime value (datetime.now()
)If both the parameters,
_from
and_to
, are not provided, then the function will return top recent 25 articles from the current datetime.
MediumList class
- class medium_api._medium_list.MediumList(list_id, get_resp, fetch_articles, fetch_users, fetch_publications, fetch_lists, save_info=False)[source]
MediumList Class
With MediumList object, you can use the following properties and methods:
medium_list._id
medium_list.info
medium_list.article_ids
medium_list.articles
medium_list.response_ids
medium_list.responses
medium_list.fetch_responses()
medium_list.fetch_articles()
Note
MediumList class is NOT intended to be used directly by importing. See
medium_api.medium.Medium.Mediumlist
.- property info
To get the MediumList-related information
- Returns:
A dictionary object containing name, description, author, claps, voters, responses_count, thumbnail, article count, etc …
- Return type:
dict
- save_info()[source]
Saves the information related to the Medium List
Note
Only after running
medium_list.save_info()
you can use the following variables:medium_list.name
medium_list.description
medium_list.author
medium_list.count
medium_list.responses_count
medium_list.claps
medium_list.voters
medium_list.created_at
medium_list.last_item_inserted_at
medium_list.thumbnail
- property article_ids
To get an array of article_ids of the articles present in the Medium List
- Returns:
A list of article_ids (str) from the Medium List.
- Return type:
list[str]
- property response_ids
To get an array of response_ids of the comments on the Medium List
- Returns:
A list of response_ids (str) from comments on the Medium List.
- Return type:
list[str]
- property articles
To get an array of Medium List’s Article objects
- Returns:
A list of Article objects from the Medium List.
- Return type:
list[Article]
- property responses
To get an array of Responses/Comments on Medium List (Article objects)
- Returns:
A list of Article objects for the comments/responses on the Medium List.
- Return type:
list[Article]
- fetch_articles(content=False, markdown=False, html=False, html_fullpage=True, html_style_file='https://mediumapi.com/styles/dark.css')[source]
To fetch all the Medium List’s articles information (using multithreading)
- Parameters:
content (bool, optional) – Set it to True if you want to fetch the textual content of the article as well. Otherwise, default is False.
markdown (bool, optional) – Set it to True if you want to fetch the markdown of the article as well. Otherwise, default is False
html (bool, optional) – Set it to True if you want to fetch the article in HTML format as well. Otherwise, default is False
html_fullpage (bool, optional) – Set it to False if you only want to fetch the HTML inside body tag of the article. Otherwise, default is True, which fetches the entire HTML of the article.
- Returns:
All the fetched information will be access via medium_list.articles.
medium_list.articles[0].title
medium_list.articles[1].claps
- Return type:
None
- fetch_responses(content=False)[source]
To fetch all the Medium List’s Responses information (using multithreading)
- Parameters:
content (bool, optional) – Set it to True if you want to fetch the textual content of the article as well. Otherwise, default is False.
- Returns:
All the fetched information will be access via medium_list.articles.
medium_list.responses[0].title
medium_list.responses[1].claps
- Return type:
None
LatestPosts class
- class medium_api._latestposts.LatestPosts(topic_slug, get_resp, fetch_articles, fetch_users, fetch_publications, fetch_lists)[source]
LatestPosts Class
With LatestPosts object, you can use the following properties and methods:
latestposts.ids
latestposts.articles
latestposts.fetch_articles()
Note
LatestPosts class is NOT intended to be used directly by importing. See
medium_api.medium.Medium.latestposts
.- property ids
To get the article_ids of the latestposts
- Returns:
Returns a list of article ids (str).
- Return type:
list[str]
- property articles
To get a list of Article objects of the latestposts
- Returns:
Returns a list of Article objects.
- Return type:
list[Article]
- fetch_articles(content=False, markdown=False, html=False, html_fullpage=True, html_style_file='https://mediumapi.com/styles/dark.css')[source]
To fetch all the latestposts articles information (multithreading)
- Parameters:
content (bool, optional) – Set it to True if you want to fetch the textual content of the article as well. Otherwise, default is False.
markdown (bool, optional) – Set it to True if you want to fetch the markdown of the article as well. Otherwise, default is False
html (bool, optional) – Set it to True if you want to fetch the article in HTML format as well. Otherwise, default is False
html_fullpage (bool, optional) – Set it to False if you only want to fetch the HTML inside body tag of the article. Otherwise, default is True, which fetches the entire HTML of the article.
- Returns:
All the fetched information will be access via latestposts.articles.
latestposts.articles[0].title
latestposts.articles[1].claps
- Return type:
None
TopWriters class
- class medium_api._top_writers.TopWriters(topic_slug: str, count: int, get_resp, fetch_users, fetch_articles, fetch_publications, fetch_lists)[source]
TopWriters Class
With TopWriters object, you can use the following properties and methods:
top_writers.ids
top_writers.users
top_writers.fetch_users()
Note
TopWriters class is NOT intended to be used directly by importing. See
medium_api.medium.Medium.top_writers
.- property ids
To get a list of top writer’s user_ids
- Returns:
A list of user_ids of the top writers for the given topic/niche.
- Return type:
list[str]
TopFeeds class
- class medium_api._topfeeds.TopFeeds(tag, mode, get_resp, fetch_articles, fetch_users, fetch_publications, fetch_lists)[source]
TopFeeds Class
With TopFeeds object, you can use the following properties and methods:
topfeeds.ids
topfeeds.articles
topfeeds.fetch_articles()
Note
TopFeeds class is NOT intended to be used directly by importing. See
medium_api.medium.Medium.topfeeds
.- property ids
To get a list of topfeeds article_ids
- Returns:
A list of article_ids (str) from the topfeeds for the given tag and mode.
- Return type:
list[str]
- property articles
To get a list of topfeeds Article objects
- Returns:
A list of Article objects from the topfeeds for the given tag and mode.
- Return type:
list[Article]
- fetch_articles(content=False, markdown=False, html=False, html_fullpage=True, html_style_file='https://mediumapi.com/styles/dark.css')[source]
To fetch all the topfeeds articles information (multithreading)
- Parameters:
content (bool, optional) – Set it to True if you want to fetch the textual content of the article as well. Otherwise, default is False.
markdown (bool, optional) – Set it to True if you want to fetch the markdown of the article as well. Otherwise, default is False
html (bool, optional) – Set it to True if you want to fetch the article in HTML format as well. Otherwise, default is False
html_fullpage (bool, optional) – Set it to False if you only want to fetch the HTML inside body tag of the article. Otherwise, default is True, which fetches the entire HTML of the article.
- Returns:
All the fetched information will be access via topfeeds.articles.
topfeeds.articles[0].title
topfeeds.articles[1].claps
- Return type:
None
RecommendedUsers class
- class medium_api._recommended_users.RecommendedUsers(tag, get_resp, fetch_articles, fetch_users, fetch_publications, fetch_lists)[source]
RecommendedUsers Class
With RecommendedUsers object, you can use the following properties and methods:
recommended_users.ids
recommended_users.users
recommended_users.fetch_users()
Note
RecommendedUsers class is NOT intended to be used directly by importing. See
medium_api.medium.Medium.recommended_users
.- property ids
To get a list of recommended_users user_ids
- Returns:
A list of user_ids (str) from the recommended_users for the given tag.
- Return type:
list[str]
RecommendedLists class
- class medium_api._recommended_lists.RecommendedLists(tag, get_resp, fetch_articles, fetch_users, fetch_publications, fetch_lists)[source]
RecommendedLists Class
With RecommendedLists object, you can use the following properties and methods:
recommended_lists.ids
recommended_lists.objs
recommended_feed.fetch_lists()
Note
RecommendedLists class is NOT intended to be used directly by importing. See
medium_api.medium.Medium.recommended_lists
.- property ids
To get a list of recommended_lists list_ids
- Returns:
An array of list_ids (str) from the recommended_lists for the given tag.
- Return type:
list[str]
- property objs
To get a list of recommended_lists MediumList objects
- Returns:
An array of MediumList objects from the recommended_lists for the given tag.
- Return type:
list[MediumList]
RecommendedFeed class
- class medium_api._recommended_feed.RecommendedFeed(tag, count, get_resp, fetch_articles, fetch_users, fetch_publications, fetch_lists)[source]
RecommendedFeed Class
With RecommendedFeed object, you can use the following properties and methods:
recommended_feed.ids
recommended_feed.articles
recommended_feed.fetch_articles()
Note
RecommendedFeed class is NOT intended to be used directly by importing. See
medium_api.medium.Medium.recommended_feed
.- property ids
To get a list of recommended_feed article_ids
- Returns:
A list of article_ids (str) from the recommended_feed for the given tag.
- Return type:
list[str]
- property articles
To get a list of recommended_feed Article objects
- Returns:
A list of Article objects from the recommended_feed for the given tag.
- Return type:
list[Article]
- fetch_articles(content=False, markdown=False, html=False, html_fullpage=True, html_style_file='https://mediumapi.com/styles/dark.css')[source]
To fetch all the recommended_feed articles information (multithreading)
- Parameters:
content (bool, optional) – Set it to True if you want to fetch the textual content of the article as well. Otherwise, default is False.
markdown (bool, optional) – Set it to True if you want to fetch the markdown of the article as well. Otherwise, default is False
html (bool, optional) – Set it to True if you want to fetch the article in HTML format as well. Otherwise, default is False
html_fullpage (bool, optional) – Set it to False if you only want to fetch the HTML inside body tag of the article. Otherwise, default is True, which fetches the entire HTML of the article.
- Returns:
All the fetched information will be access via recommended_feed.articles.
recommended_feed.articles[0].title
recommended_feed.articles[1].claps
- Return type:
None
ArchivedArticles class
- class medium_api._archived_articles.ArchivedArticles(tag, count, year, month, next, get_resp, fetch_articles, fetch_users, fetch_publications, fetch_lists)[source]
ArchivedArticles Class
With ArchivedArticles object, you can use the following properties and methods:
archived_articles.ids
archived_articles.articles
archived_articles.fetch_articles()
Note
ArchivedArticles class is NOT intended to be used directly by importing. See
medium_api.medium.Medium.archived_articles
.- property ids
To get a list of archived_articles article_ids
- Returns:
A list of article_ids (str) from the archived_articles for the given tag.
- Return type:
list[str]
- property articles
To get a list of archived_articles Article objects
- Returns:
A list of Article objects from the archived_articles for the given tag.
- Return type:
list[Article]
- fetch_articles(content=False, markdown=False, html=False, html_fullpage=True, html_style_file='https://mediumapi.com/styles/dark.css')[source]
To fetch all the archived_articles information (using multithreading)
- Parameters:
content (bool, optional) – Set it to True if you want to fetch the textual content of the article as well. Otherwise, default is False.
markdown (bool, optional) – Set it to True if you want to fetch the markdown of the article as well. Otherwise, default is False
html (bool, optional) – Set it to True if you want to fetch the article in HTML format as well. Otherwise, default is False
html_fullpage (bool, optional) – Set it to False if you only want to fetch the HTML inside body tag of the article. Otherwise, default is True, which fetches the entire HTML of the article.
- Returns:
All the fetched information will be access via archived_articles.articles.
archived_articles.articles[0].title
archived_articles.articles[1].claps
- Return type:
None