API#
API Instance#
- class redgifs.API(session=None, *, proxy=None, proxy_auth=None)#
The API Instance to get information from the RedGifs API.
Note
If you are using this library in an asynchronous code, you should refer the Async API section.
- Parameters:
session (Optional[
requests.Session]) – A session object that can be provided to do the requests. If not provided, a new session object is created.proxy (Optional[
str]) – A valid proxy URL.proxy_auth (Optional[
ProxyAuth]) – The proxy auth to provide if the proxy requires it.
- login()#
A method to login to RedGifs with a temporary token. You must use this method after initialising the
APIclass for this library to function properly.- Return type:
API- The properly initialised API class.
- get_tags()#
Get all available RedGifs Tags.
- Return type:
List[Dict[str, Union[str, int]]]
- get_gif(id)#
Get details of a single GIF using its ID.
If the URL is
https://redgifs.com/watch/abcxyzthen the ID isabcxyz.
- get_trending_tags()#
Get the trending searches on RedGifs.
- Returns:
A list of dicts containing the tag name and count:
[ { "name": "r/CaughtPublic", "count": 2034 }, { "name": "Vintage", "count": 19051 }, ... ]
- Return type:
List[Dict[str, Union[str, int]]]
- get_top_this_week(count=30, page=1, type=MediaType.GIF)#
Get media from “Top This Week” section.
- Parameters:
- Return type:
SearchResult- Top this week results.
- fetch_tag_suggestions(query)#
Get tag suggestions from RedGifs.
Note
It’s advised to use
Tags.search()to prevent multiple API calls to redgifs.com.- Parameters:
query (
str) – The tag name to look for.- Return type:
List[
TagSuggestion] - A list ofTagSuggestionwith tag name and count.
- search(search_text, *, order=Order.TRENDING, count=40, page=1)#
Search for GIFs.
- Parameters:
- Return type:
SearchResult- The search result.
- search_gif(search_text, *, order=Order.TRENDING, count=40, page=1)#
Search for GIFs.
- Parameters:
- Return type:
SearchResult- The search result.
- search_creators(*, page=1, order=Order.LATEST, verified=False, tags=None)#
Search for some RedGifs Creators.
- Parameters:
page (Optional[
int]) – The result in page number to return.order (Optional[
Order]) – The order of the creators to return.verified (Optional[
bool]) – Wheather to only return verified creators.tags (Optional[List[
str]]) – A list of tags to look for. Narrows down the results to creators that have contents with the given tags.
- Return type:
CreatorsResult- The search result.
- search_creator(username, *, page=1, count=80, order=Order.LATEST, type=MediaType.GIF)#
Search for a single RedGifs creator/user by username.
- Parameters:
username (
str) – The username of the creator/user.page (
int) – The current page number of the creator/user’s profile.count (
int) – The total amount of GIFs to return.order (
Order) – The order to return creator/user’s GIFs.type (
MediaType) – Whether to return image or GIF results. By default returns GIFs.
- Return type:
CreatorResult- The creator/user searched for.
- search_user(username, *, page=1, count=80, order=Order.LATEST, type=MediaType.GIF)#
Search for a single RedGifs creator/user by username.
- Parameters:
username (
str) – The username of the creator/user.page (
int) – The current page number of the creator/user’s profile.count (
int) – The total amount of GIFs to return.order (
Order) – The order to return creator/user’s GIFs.type (
MediaType) – Whether to return image or GIF results. By default returns GIFs.
- Return type:
CreatorResult- The creator/user searched for.
- get_user(username)#
Get details of a user on RedGifs.
- search_image(search_text, *, order=Order.TRENDING, count=40, page=1)#
Search for images.
- Parameters:
- Return type:
SearchResult- The search result.
- download(url, fp)#
A friendly method to download a RedGifs media.
Example:
api = redgifs.API() api.login() hd_url = api.search("query").gifs[0].urls.hd api.download(hd_url, "video.mp4")
Note
You should use this method to download any media from RedGifs because RedGifs does validation on User-Agents and other params. If you try to download it by using any other means, it will return 403 error.
- Parameters:
url (
str) – A valid RedGifs URL.fp (Union[
io.BufferedIOBase,os.PathLike]) – The file-like object to save this asset to or the filename to use. If a filename is passed then a file is created with that filename and used instead.
- search_niches(query, *, order=NicheOrder.BEST_MATCH, count=40, page=1)#
Search for niches.
- get_niche(niche_id, *, order=NicheGifOrder.TRENDING, count=40, page=1)#
Search for a single niche’s GIFs
- Parameters:
- Return type:
SearchResult- The search result.
- close()#
Closes the API session.
Async API#
Same as API but for usage in async context.
- class redgifs.aio.API(session=None, *, proxy=None, proxy_auth=None)#
The API Instance to get information from the RedGifs API.
- Parameters:
session (Optional[
aiohttp.ClientSession]) – Anaiohttp.ClientSessionobject that can be provided to do the requests. If not provided, a new session object is created.proxy (Optional[
str]) – A valid proxy URL.proxy_auth (Optional[
ProxyAuth]) – The proxy auth to provide if the proxy requires it.
- async login()#
A method to login to RedGifs with a temporary token. You must use this method after initialising the
APIclass for this library to function properly.- Return type:
API- The properly initialised API class.
- async get_tags()#
Get all available RedGifs Tags.
- Return type:
List[Dict[str, Union[str, int]]]
- async get_gif(id)#
Get details of a single GIF using its ID.
If the URL is
https://redgifs.com/watch/abcxyzthen the ID isabcxyz.
- async get_trending_tags()#
Get the trending searches on RedGifs.
- Returns:
A list of dicts containing the tag name and count:
[ { "name": "r/CaughtPublic", "count": 2034 }, { "name": "Vintage", "count": 19051 }, ... ]
- Return type:
List[Dict[str, Union[str, int]]]
- async get_top_this_week(count=30, page=1, type=MediaType.GIF)#
Get media from “Top This Week” section.
- Parameters:
- Return type:
SearchResult- Top this week results.
- async fetch_tag_suggestions(query)#
Get tag suggestions from RedGifs.
Note
It’s advised to use
Tags.search()to prevent multiple API calls to redgifs.com.- Parameters:
query (
str) – The tag name to look for.- Return type:
List[
TagSuggestion] - A list ofTagSuggestionwith tag name and count.
- async search(search_text, *, order=Order.TRENDING, count=40, page=1)#
Search for GIFs.
- Parameters:
- Return type:
SearchResult- The search result.
- async search_gif(search_text, *, order=Order.TRENDING, count=40, page=1)#
Search for GIFs.
- Parameters:
- Return type:
SearchResult- The search result.
- async search_creators(*, page=1, order=Order.LATEST, verified=False, tags=None)#
Search for some RedGifs Creators.
- Parameters:
page (Optional[
int]) – The result in page number to return.order (Optional[
Order]) – The order of the creators to return.verified (Optional[
bool]) – Wheather to only return verified creators.tags (Optional[List[
str]]) – A list of tags to look for. Narrows down the results to creators that have contents with the given tags.
- Return type:
CreatorsResult- The search result.
- async search_creator(username, *, page=1, count=80, order=Order.LATEST, type=MediaType.GIF)#
Search for a single RedGifs creator/user by username.
- Parameters:
username (
str) – The username of the creator/user.page (
int) – The current page number of the creator/user’s profile.count (
int) – The total amount of GIFs to return.order (
Order) – The order to return creator/user’s GIFs.type (
MediaType) – Whether to return image or GIF results. By default returns GIFs.
- Return type:
CreatorResult- The creator/user searched for.
- async search_user(username, *, page=1, count=80, order=Order.LATEST, type=MediaType.GIF)#
Search for a single RedGifs creator/user by username.
- Parameters:
username (
str) – The username of the creator/user.page (
int) – The current page number of the creator/user’s profile.count (
int) – The total amount of GIFs to return.order (
Order) – The order to return creator/user’s GIFs.type (
MediaType) – Whether to return image or GIF results. By default returns GIFs.
- Return type:
CreatorResult- The creator/user searched for.
- async get_user(username)#
Get details of a user on RedGifs.
- async search_image(search_text, *, order=Order.TRENDING, count=40, page=1)#
Search for images.
- Parameters:
- Return type:
SearchResult- The search result.
- async download(url, fp)#
A friendly method to download a RedGifs media.
Example:
from redgifs.aio import API api = API() await api.login() hd_url = await api.search("query").gifs[0].urls.hd await api.download(hd_url, "video.mp4")
Note
You should use this method to download any media from RedGifs because RedGifs does validation on User-Agents and other params. If you try to download it by using any other means, it will return a 403 error.
- Parameters:
url (
str) – A valid RedGifs URL.fp (Union[
io.BufferedIOBase,os.PathLike]) – The file-like object to save this asset to or the filename to use. If a filename is passed then a file is created with that filename and used instead.
- async search_niches(query, *, order=NicheOrder.BEST_MATCH, count=40, page=1)#
Search for niches.
- async get_niche(niche_id, *, order=NicheGifOrder.TRENDING, count=40, page=1)#
Search for a single niche’s GIFs
- Parameters:
- Return type:
SearchResult- The search result.
- async close()#
Closes the API session.
Proxy Auth#
A utility class to provide proxy authorization.
Models#
Models are classes that are received from Redgifs and are not meant to be created by the user of the library.
- class redgifs.models.URL#
The different types of URLs.
Warning
sd,hd,poster,thumbnail, andvthumbnailleaks your IP address in the URL. If you want to display the URLs to the end user consider usingweb_urlorembed_urlinstead.
- class redgifs.models.GIF#
The GIF returned from RedGifs.
- create_date#
The date when the GIF is published.
- Type:
Optional[
datetime.datetime]
- class redgifs.models.TagSuggestion#
The tag suggestion results.
- class redgifs.models.Image#
The image returned from RedGifs.
- create_date#
The date when the image is published.
- Type:
Optional[
datetime.datetime]
- class redgifs.models.User#
The user’s information returned from RedGifs.
- creation_time#
The user’s account creation time.
- Type:
Optional[
datetime.datetime]
- class redgifs.models.SearchResult#
The result you have searched. This is returned in
search().
- class redgifs.models.CreatorsResult#
The creator results searched for.
- class redgifs.models.CreatorResult#
The creator result searched for.
Enums#
Exceptions#
- exception redgifs.RedGifsError#
Base class for all redgifs errors.
- exception redgifs.InvalidTag(tag)#
Exception raised when no match was found for a tag.
- exception redgifs.HTTPException(response, json)#
Exception raised when an HTTP Exception occurs.
- response#
The response of the failed HTTP request. It may be either
requests.Responseoraiohttp.ClientResponse.- Type: