GIPHY Alt Text for GIFs is now available! Email us to learn more at bd.team@giphy.com.
GIPHY Clips (GIFs with Sound)have arrived! Learn about adding Clips to your app in our documentation!
Need to move your project from Tenor to GIPHY?   Check out our  migration guide!
logo

Code Example

Below are code samples for using the Search Endpoint in Python, JavaScript, Ruby, PHP and the command line on connecting to the API to make a search query for "Ryan Gosling."

Copy Code
1# python
2import json
3from urllib import parse, request
4
5url = "http://api.giphy.com/v1/gifs/search"
6
7params = parse.urlencode({
8 "q": "ryan gosling",
9 "api_key": "YOUR_API_KEY",
10 "limit": "5"
11})
12
13with request.urlopen("".join((url, "?", params))) as response:
14 data = json.loads(response.read())
15
16print(json.dumps(data, sort_keys=True, indent=4))

Below are code samples for using the Upload Endpoint to upload a remote file.

Copy Code
1# python
2import json
3from urllib import request
4
5url = "http://upload.giphy.com/v1/gifs"
6
7values = {
8 "api_key": "YOUR_API_KEY",
9 "username": "JoeCool3000",
10 "source_image_url": "http://www.mysite.com/myfile.mp4"
11}
12
13headers = {
14 "Content-Type": "application/json",
15 "Accept": "application/json",
16}
17
18data = json.dumps(values).encode("utf-8")
19
20req = request.Request(url, data, headers)
21with request.urlopen(req) as res:
22 print(res.read().decode())

Below are code samples for using the Upload Endpoint to upload a local file.

Copy Code
1import requests
2url = "https://upload.giphy.com/v1/gifs"
3file_path = "C:\test.gif"
4api_key = "YourApiKey"
5
6with open(file_path, 'rb') as file:
7 data = { 'api_key': api_key }
8 files = { 'file': file }
9 response = requests.post(url, data=data, files=files)
10 print(response.text)