Package: giphypop
giphypopis a wrapper around theGiphyapi. It aims to provide a more
intuitive, pythonic way for interacting with theGiphyapi.Requirements, Installing, and CompatibilityThe only requirement, included inrequirements.txtis forrequests. If you
are using pip, you can installgiphypop:$pipinstallrequestsgiphypopAlternatively:$pipinstallrequests$pipinstall-egit+https://github.com/shaunduncan/giphypop.git#egg=giphypopThen you should be off and running.giphypophas been tested against python
versions 2.6, 2.7, 3.2 and 3.3.Getting StartedUsinggiphypopis straightforward and aims provide interaction with
the api without any regard to large bits of JSON. To get started, you
can test out various features using the include api key. You should be
warned, however, that whileGiphyhas been so kind as have a public
“testing” key, it may be turned off in the future. See theapi docsfor more information.The entry point for interacting withGiphyapi is thegiphypop.Giphyclass. This class optionally accepts two arguments:api_keyandstrict.
Theapi_keyagument, when not preset, will default to the public key
(see above). Thestrictargument controls how you expect the api to
react when no results are returned. If enabled, an exception is raised,
otherwise,Noneis returned.>>>importgiphypop>>>g=giphypop.Giphy()Now you’re ready to get started. There are a few key methods of thegiphypop.Giphyobject that you’ll want to know aboutsearchSearch for gifs with a given word or phrase. Punctuation is ignored.
By default, this will perform atermsearch. If you want to search
by phrase, use thephrasekeyword argument. What’s the difference
betweentermandphrasesearches? Simple: a term search will
return results matching any words given, whereas a phrase search will
match all words.Note that this method is agiphypop.GiphyImagegenerator that
automatically handles api paging. Optionally accepts a limit that will
terminate the generation after a specified number of results have been
yielded. This defaults to 25 results; a None implies no limitterm: Search term or terms, stringphrase: Search phrase, stringlimit: Maximum number of results to yield, integersearch_listSuppose you expect thesearchmethod to just give you a list rather
than a generator. This method will have that effect. Equivalent to:>>>g=giphypop.Giphy()>>>results=[xforxing.search('foo')]translateRetrieve a single image that represents a transalation of a term or
phrase into an animated gif. Punctuation is ignored. By default, this
will perform atermtranslation. If you want to translate by phrase,
use thephrasekeyword argument.term: Search term or terms, stringphrase: Search phrase, stringstrict: Whether an exception should be raised when no results, booleangifRetrieves a specifc gif from giphy based on unique idgif_id: Unique giphy gif ID, stringstrict: Whether an exception should be raised when no results, booleanscreensaverReturns a random giphy image, optionally based on a search of a given tag.
Note that this method will both query for a screensaver image and fetch the
full details of that image (2 request calls)tag: Limit random gifs returned by a tag, stringstrict: Whether an exception should be raised when no results, booleanrandom_gifAn alias ofgiphypop.Giphy.screensaveruploadUploads a video or gif to giphy. Once the upload has completed, requests the
full gif details and returns a GiphyImage (2 request calls).tags: A list of tags to use on the uploaded gif, listfile_path: The path to the file to upload, stringusername: The username of the account to upload to when using your own API key, stringNoteThe above methods ofgiphypop.Giphyare also exposed at the module
level for your convenience. The only difference is that they also
accept anapi_keykeyword argument. For example:>>>fromgiphypopimporttranslate>>>img=translate('foo',api_key='bar')Handling ResultsAll results that represent a single image are wrapped in agiphypop.GiphyImageobject. This object acts like a dictionary, but
also exposes keys as attributes. Note, that these arenota direct
mirror of api response objects; their goal is to be simpler. Structure
follows this layout:<Result Object>
    - id
    - type: image type (i.e. gif)
    - url: URL to giphy page
    - raw_data: copy of original data response from giphy (JSON)
    - fullscreen: bit.ly link to giphy fullscreen gif
    - tiled: bit.ly link to giphy tiled gif
    - bitly: bit.ly version of `url`
    - media_url: URL directly to image (original size)
    - frames: number of frames
    - height: image height (original image)
    - width: image width (original image)
    - size: filesize (in bytes, original image)
    - fixed_height: (variable width @ 200px height)
        - url: URL directly to image
        - width: image width
        - height: image height
        - downsampled:
            - url: URL directly to image
            - width: image width
            - height: image height
        - still: (a still image of gif)
            - url: URL directly to image
            - width: image width
            - height: image height
    - fixed_width: (variable height @ 200px width)
        - url: URL directly to image
        - width: image width
        - height: image height
        - downsampled:
            - url: URL directly to image
            - width: image width
            - height: image height
        - still: (a still image of gif)
            - url: URL directly to image
            - width: image width
            - height: image heightFor example:>>>fromgiphypopimporttranslate>>>img=translate('foo')>>>img.url'http://giphy.com/foo/bar/baz'>>>img.width200>>>img.fixed_height.downsampled.url'http://giphy.com/foo/bar/downsampled'UploadingThe Giphy API will accept uploads of gifs or videos. You are able to upload
using the public API key, but you won’t be able to assign them to your username
or delete them. In order to upload to your account, set theusernamewhen you
and the API key when you upload.For example:>>>fromgiphypopimportupload>>>gif=upload(["foo","bar"],"mycat.gif")>>>gifGiphyImage<26BRvG76mOYcvRxss>athttp://giphy.com/gifs/bar-foo-26BRvG76mOYcvRxssOr using your own API key to upload to your own account:>>>fromgiphypopimportupload>>>gif=upload(["foo","bar"],"mycat.gif",username="gifsarefun",api_key="abcdef12345678")>>>gifGiphyImage<26BRvG76mOYcvRxss>athttp://giphy.com/gifs/bar-foo-26BRvG76mOYcvRxssChangelog0.1Initial VersionContribution and LicenseDeveloped byShaun Duncanand is licensed under the terms of a MIT license.
Contributions are welcomed and appreciated!