python-gyazo¶
A Python wrapper for Gyazo API.
Contents¶
Quickstart¶
Requirements¶
- Python 2.7+
- Python 3.4+
Installation¶
pip install python-gyazo
Usage¶
At first, you must create an application and get an access token from https://gyazo.com/oauth/applications
from gyazo import Api
client = Api(access_token='YOUR_ACCESS_TOKEN')
### Get a list of images
images = client.get_image_list()
for image in images:
print(str(image))
### Using an image model
image = images[0]
print("Image ID: " + image.image_id)
print("URL: " + image.url)
### Download an image
if image.url:
with open(image.filename, 'wb') as f:
f.write(image.download())
### Upload an image
with open('sample.png', 'rb') as f:
image = client.upload_image(f)
print(image.to_json())
### Delete an image
client.delete_image('IMAGE_ID')
### oEmbed
image = images[0]
print(client.get_oembed(image.permalink_url))
Reference¶
gyazo.Api class¶
-
class
gyazo.
Api
(client_id=None, client_secret=None, access_token=None, api_url='https://api.gyazo.com', upload_url='https://upload.gyazo.com')¶ Bases:
object
A Python interface for Gyazo API
-
delete_image
(image_id)¶ Delete an image
Parameters: image_id – Image ID
-
get_image_list
(page=1, per_page=20)¶ Return a list of user’s saved images
Parameters: - page – (optional) Page number (default: 1)
- per_page – (optional) Number of images per page (default: 20, min: 1, max: 100)
-
get_oembed
(url)¶ Return an oEmbed format json dictionary
Parameters: url – Image page URL (ex. http://gyazo.com/xxxxx)
-
upload_image
(image_file, referer_url=None, title=None, desc=None, created_at=None, collection_id=None)¶ Upload an image
Parameters: - image_file – File-like object of an image file
- referer_url – Referer site URL
- title – Site title
- desc – Comment
- created_at – Image’s created time in unix time
- collection_id – Collection ID
-
gyazo.Image class¶
-
class
gyazo.
Image
(**kwargs)¶ Bases:
object
A class representing an image of Gyazo
-
created_at
= None¶ The time this image was created
-
download
()¶ Download an image file if it exists
Raises: GyazoError –
-
download_thumb
()¶ Download a thumbnail image file
Raises: GyazoError –
-
filename
¶ An image filename
Getter: Return an image filename if it exists
-
static
from_dict
(data)¶ Create a new instance from dict
Parameters: data – A JSON dict
-
image_id
= None¶ An image ID
-
local_created_at
¶ The time this image was created in local time zone
Getter: Return the time this image was created in local time zone
-
permalink_url
= None¶ A permalink URL
-
thumb_filename
¶ A thumbnail image filename
Getter: Return a thumbnail filename
-
thumb_url
= None¶ A thumbnail URL
-
to_dict
()¶ Return a dict representation of this instance
-
to_json
(indent=None, sort_keys=True)¶ Return a JSON string representation of this instance
Parameters: - indent – specify an indent level or a string used to indent each level
- sort_keys – the output is sorted by key
-
type
= None¶ A type of the image
-
url
= None¶ An image URL
-
gyazo.ImageList class¶
-
class
gyazo.
ImageList
(**kwargs)¶ Bases:
object
A class representing a list of gyazo.Image
-
current_page
= None¶ Current page number
-
static
from_list
(data)¶ Create a new instance from list
Parameters: data – A JSON list
-
has_next_page
()¶ Whether there is a next page or not
Getter: Return true if there is a next page
-
has_previous_page
()¶ Whether there is a previous page or not
Getter: Return true if there is a previous page
-
images
= None¶ List of images
-
num_pages
¶ The number of pages
Getter: Return the number of pages
-
per_page
= None¶ The number of images per page
-
set_attributes_from_headers
(headers)¶ Set instance attributes with HTTP header
Parameters: headers – HTTP header
-
to_json
(indent=None, sort_keys=True)¶ Return a JSON string representation of this instance
Parameters: - indent – specify an indent level or a string used to indent each level
- sort_keys – the output of dictionaries is sorted by key
-
total_count
= None¶ The number of images
-
user_type
= None¶ User type
-
License¶
MIT License. Please see LICENSE.
The following software may be included in this application: Masonry. This software contains the following license and notice below:
The MIT License (MIT)
Copyright © 2015 David DeSandro
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.