Skip to content

API Reference

RG TQ UG edited this page Feb 13, 2016 · 3 revisions

#The API Object The API object is where most of the functions will be called from. Creating an API object takes two parameters, user and key, which are your Danbooru username and API key respectively. The API object uses your credentials to interact with Danbooru.

##Variables ###user Your username on Danbooru.

###key Your API key on Danbooru.

##Methods ###create_image(self, image_id) Takes an image ID and returns a post object.

###search_images(self, tag_string, pages) Takes a string of tags formatted in the form of a normal Danbooru search, tag_string, and an int representing pages, and returns a list of post objects equal to 24 * pages, or less if there aren't that many images meeting the criteria hosted on Danbooru.

###upload(self, filepath, rating, tag_string, source="") Uploads an image to Danbooru. filepath is the local path to the file on your machine. rating is a string that describes the image's rating; enter safe for SFW images, enter questionable for slightly NSFW images, and enter explicit for NSFW images - it must be one of these three or the request will not go through. The tag_string variable is a string of tags formatted as you would a normal web upload. source is the source URL, where you originally got the image from. It isn't necessary but recommended.

###get_dmails(self) Returns a list of dmail objects from your own inbox.

###send_dmail(self, title, body, to) Sends a dmail to to with the title title, the message content being body.

###create_entry(self, title, body) Creates a wiki entry with the title title and the entry content being body.

###get_entries(self, terms) Return a list of entry objects, which are wiki entries, matching your search terms.

#The post Object The post object is created through interactions with a user object. These represent a single image post on Danbooru.

##Variables ###image_id The image ID.

###creation_date The date when the post was created.

###uploader_id The uploader's user ID.

###score How highly (or lowly) the image is rated by Danbooru's users.

###source The source URL for the image; where it was originally posted.

###md5 The MD5 hash of the image, used as the title when downloading.

###rating If the image is 'safe', 'questionable', or 'explicit'.

###width The image's width, in pixels.

###height The image's height, in pixels.

###tag_string A string representing all the tags the image has.

###file_ext The filetype, such as 'gif', 'jpg', or 'png'.

###pixiv_id If the artist has an ID on pixiv, it goes here.

###uploader_name The username of the person who uploaded the image.

###string_artists All the known artists who contributed to the image, in a string.

###artists The same as above, but in a list.

###string_characters All the known characters in the image, in a string.

###characters The same as above, but in a list.

###string_copyrights The copyrights, series, or canon sources the image is from, in a string.

###copyrights The same as above, but in a list.

###string_general All the tags that aren't copyright, character, or artist, in a string.

###general_tags The same as above, but in a list.

###file_url The URL of the file.

###large_file_url If the image is high-resolution, or absurdly large, file_url will be a shrunken down version of the original and large_file_url will be the original size. Otherwise, this is the same as file_url.

##Methods ###download_image(self, path=None) Downloads the image to the specified path, or if left blank, the same directory as the running script.

###download_large_image(self, path=None): The same as above, but uses the large_file_url variable.

###comment_on_post(self, comment) Comments on the post with the string comment.

###rate_post_up(self) Upvotes the post.

###rate_post_down(self) Downvotes the post.

###flag_post(self, reason) Flags the post for deletion with the specified reason.

###favorite_post(self) Adds the post to your list of favorite posts.

###unfavorite_post(self) Removes the post from your list of favorite posts.

#The dmail Object A dmail is a direct message on Danbooru. You can only interact with dmails you've sent or recieved.

##Variables ###message_id The ID of the message.

###owner_id The ID of the user that owns the message.

###from_id The ID of the user that sent the message.

###to_id The ID of the user that recieved the message.

###title The title of the message.

###body The content of the message.

###is_read A boolean that indicates if the message has been read.

###is_deleted A boolean that indicates if the message has been deleted.

##Methods ###delete_msg(self) Deletes the message from your inbox. You cannot access it on web anymore and cannot access some variables through the API.

#The entry Object This represents a wiki entry on Danbooru.

##Variables ###id_number The ID of the wiki entry.

###created_at When the wiki page was created.

###last_update When the wiki page was last updated.

###title The title of the wiki page.

###body The content of the wiki page.

###creator_id The ID of the user who created the wiki page.

###is_locked A boolean representing whether the page is locked or not.

###other_names Other names for the wiki entry.

###creator_name The username of the user who created the wiki page.

##Methods ###update_title(self, title) Replaces the title of the wiki entry with title.

###update_body(self, body) Replaces the body of the wiki entry with body.

Clone this wiki locally