redgifs Python Wrapper

repository·main·Indexed 41 days ago

https://github.com/scrazzz/redgifs

An async and sync Python wrapper for the RedGIFs API, providing tools to search, interact with, and download content from the RedGIFs platform. It includes a command-line interface (CLI) for downloading GIFs and images from URLs or user profiles, as well as programmatic access via redgifs.API and redgifs.aio.API.

Tokens
8.5K
Snippets
45
Records
65
Agent score
50%

What's inside redgifs

  1. Understand RedGifs Models

    main

    Models are data classes representing objects received from the RedGifs API. Note: These models are not intended to be instantiated by the user; they are populated by the library during API responses.

    Available models include:

    • URL
    • GIF
    • TagSuggestion
    • Image
    • User
    • SearchResult
    • CreatorsResult
    • CreatorResult
  2. Install redgifs

    main

    Install the stable version of redgifs from PyPI using pip. The package requires Python 3.8 or higher.

    To install the development version directly from GitHub, use the git URL.

    # Stable version
    pip install -U redgifs
    
    # Development version
    pip install -U git+https://github.com/scrazzz/redgifs
  3. Migrate Order enum members in v2.1+

    main
    Starting in v2.1, Order enum members were changed to uppercase to follow PEP8 guidelines. While lowercase members will work until v2.2 (with a DeprecationWarning), you should switch to uppercase members immediately (e.g., Order.BEST, Order.LATEST).
  4. Install the redgifs library

    main

    You can install the redgifs library using pip. Choose either the stable version or the development version from GitHub.

    # Install the latest stable version
    $ pip install -U redgifs
    
    # Install the development version
    $ pip install -U git+https://github.com/scrazzz/redgifs
  5. Migrate MediaType enum in v2.x

    main

    In v2.x, the enum used for methods like API.get_top_this_week() and API.search_creator() has been renamed from Type to MediaType. You must update your imports and use the new name. Note that enum members are also expected to be uppercase.

    from redgifs import API
    # Old: from redgifs import Type
    from redgifs import MediaType
    
    api = redgifs.API().login()
    # Use MediaType instead of Type
    api.search_creator('username', type=MediaType.IMAGE)
  6. Initialize and login to the RedGifs API

    main

    To use the redgifs library, you must first instantiate the API class and then call the login() method. The login() method obtains a temporary token required for the library to function properly. You can optionally provide a requests.Session, a proxy URL, or proxy_auth during initialization.

    Note: If you are working in an asynchronous environment, you should use the Async API instead of this synchronous client.

    import redgifs
    
    api = redgifs.API()
    api.login()
  7. Download GIFs via CLI examples

    main

    Download multiple GIFs

    $ redgifs https://redgifs.com/watch/abc https://redgifs.com/watch/xyz https://redgifs.com/watch/def

    Download GIFs to a specific folder

    $ redgifs https://redgifs.com/watch/xyz --quality sd --folder Homework

    Download GIFs from a text file

    $ redgifs -i urls.txt

    Download all GIFs from a user's profile

    $ mkdir rg_vids
    $ redgifs https://redgifs.com/users/usernamethatexists -f rg_vids
  8. Use redgifs asynchronously

    main

    For asynchronous workflows, import API from redgifs.aio. All network-related methods must be awaited. Ensure you call await api.login() and await api.close() to manage the session lifecycle.

    import asyncio
    from redgifs.aio import API # note this
    
    async def main():
        api = API()
        await api.login() # Login with temporary token
        response = await api.search('3D')
        print(response)
        await api.close()
    
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())
  9. Use redgifs synchronously

    main

    For synchronous workflows, import redgifs and use the redgifs.API class. You must call .login() (which uses a temporary token) before making requests, and call .close() when finished.

    import redgifs
    
    api = redgifs.API()
    api.login() # Login with temporary token
    response = api.search('3D')
    print(response)
    api.close()