{"id":17197149,"url":"https://github.com/michaelhelmick/python-tumblpy","last_synced_at":"2025-04-09T12:06:31.837Z","repository":{"id":2232215,"uuid":"3185519","full_name":"michaelhelmick/python-tumblpy","owner":"michaelhelmick","description":"A Python Library to interface with Tumblr v2 REST API \u0026 OAuth","archived":false,"fork":false,"pushed_at":"2017-02-08T22:01:38.000Z","size":69,"stargazers_count":122,"open_issues_count":2,"forks_count":36,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-04-02T10:12:17.574Z","etag":null,"topics":["api","python","tumblr","tumblr-api"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/michaelhelmick.png","metadata":{"files":{"readme":"README.rst","changelog":"HISTORY.rst","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-01-15T19:54:59.000Z","updated_at":"2023-08-28T00:04:50.000Z","dependencies_parsed_at":"2022-07-31T12:08:04.778Z","dependency_job_id":null,"html_url":"https://github.com/michaelhelmick/python-tumblpy","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelhelmick%2Fpython-tumblpy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelhelmick%2Fpython-tumblpy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelhelmick%2Fpython-tumblpy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelhelmick%2Fpython-tumblpy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/michaelhelmick","download_url":"https://codeload.github.com/michaelhelmick/python-tumblpy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248036063,"owners_count":21037092,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","python","tumblr","tumblr-api"],"created_at":"2024-10-15T01:55:35.580Z","updated_at":"2025-04-09T12:06:31.820Z","avatar_url":"https://github.com/michaelhelmick.png","language":"Python","readme":"Tumblpy\n=======\n\n.. image:: https://pypip.in/d/python-tumblpy/badge.png\n        :target: https://crate.io/packages/python-tumblpy/\n\nTumblpy is a Python library to help interface with Tumblr v2 REST API \u0026 OAuth\n\nFeatures\n--------\n\n* Retrieve user information and blog information\n* Common Tumblr methods\n   - Posting blog posts\n   - Unfollowing/following blogs\n   - Edit/delete/reblog posts\n   - And many more!!\n* Photo Uploading\n* Transparent *Python 3* Support!\n\n\nInstallation\n------------\n\nInstalling Tumbply is simple:\n::\n\n    $ pip install python-tumblpy\n\n\nUsage\n-----\n\nImporting\n~~~~~~~~~\n\n.. code-block:: python\n\n    from tumblpy import Tumblpy\n\nAuthorization URL\n~~~~~~~~~~~~~~~~~\n\n.. code-block:: python\n\n    t = Tumblpy(YOUR_CONSUMER_KEY, YOUR_CONSUMER_SECRET)\n\n    auth_props = t.get_authentication_tokens(callback_url='http://michaelhelmick.com')\n    auth_url = auth_props['auth_url']\n\n    OAUTH_TOKEN_SECRET = auth_props['oauth_token_secret']\n\n    print 'Connect with Tumblr via: %s' % auth_url\n\nOnce you click \"Allow\" be sure that there is a URL set up to handle getting finalized tokens and possibly adding them to your database to use their information at a later date.\n\nHandling the Callback\n~~~~~~~~~~~~~~~~~~~~~\n\n.. code-block:: python\n\n    # OAUTH_TOKEN_SECRET comes from the previous step\n    # if needed, store those in a session variable or something\n\n    # oauth_verifier and OAUTH_TOKEN are found in your callback url querystring\n    # In Django, you'd do something like\n    # OAUTH_TOKEN = request.GET.get('oauth_token')\n    # oauth_verifier = request.GET.get('oauth_verifier')\n\n\n    t = Tumblpy(YOUR_CONSUMER_KEY, YOUR_CONSUMER_SECRET,\n                OAUTH_TOKEN, OAUTH_TOKEN_SECRET)\n\n    authorized_tokens = t.get_authorized_tokens(oauth_verifier)\n\n    final_oauth_token = authorized_tokens['oauth_token']\n    final_oauth_token_secret = authorized_tokens['oauth_token_secret']\n\n    # Save those tokens to the database for a later use?\n\nGetting some User information\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n.. code-block:: python\n\n    # Get the final tokens from the database or wherever you have them stored\n\n    t = Tumblpy(YOUR_CONSUMER_KEY, YOUR_CONSUMER_SECRET,\n                OAUTH_TOKEN, OAUTH_TOKEN_SECRET)\n\n    # Print out the user info, let's get the first blog url...\n    blog_url = t.post('user/info')\n    blog_url = blog_url['user']['blogs'][0]['url']\n\nGetting posts from a certain blog\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n.. code-block:: python\n\n    # Assume you are using the blog_url and Tumblpy instance from the previous section\n    posts = t.get('posts', blog_url=blog_url)\n    print posts\n    # or you could use the `posts` method\n    audio_posts = t.posts(blog_url, 'audio')\n    print audio_posts\n    all_posts = t.posts(blog_url)\n    print all_posts\n\nCreating a post with a photo\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n::\n\n    # Assume you are using the blog_url and Tumblpy instance from the previous sections\n\n    photo = open('/path/to/file/image.png', 'rb')\n    post = t.post('post', blog_url=blog_url, params={'type':'photo', 'caption': 'Test Caption', 'data': photo})\n    print post  # returns id if posted successfully\n\nPosting an Edited Photo *(This example resizes a photo)*\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n.. code-block:: python\n\n    # Assume you are using the blog_url and Tumblpy instance from the previous sections\n\n    # Like I said in the previous section, you can pass any object that has a\n    # read() method\n\n    # Assume you are working with a JPEG\n\n    from PIL import Image\n    from StringIO import StringIO\n\n    photo = Image.open('/path/to/file/image.jpg')\n\n    basewidth = 320\n    wpercent = (basewidth / float(photo.size[0]))\n    height = int((float(photo.size[1]) * float(wpercent)))\n    photo = photo.resize((basewidth, height), Image.ANTIALIAS)\n\n    image_io = StringIO.StringIO()\n    photo.save(image_io, format='JPEG')\n\n    image_io.seek(0)\n\n    try:\n        post = t.post('post', blog_url=blog_url, params={'type':'photo', 'caption': 'Test Caption', 'data': photo})\n        print post\n    except TumblpyError, e:\n        # Maybe the file was invalid?\n        print e.message\n\nFollowing a user\n~~~~~~~~~~~~~~~~\n\n.. code-block:: python\n\n    # Assume you are using the blog_url and Tumblpy instance from the previous sections\n    try:\n        follow = t.post('user/follow', params={'url': 'tumblpy.tumblr.com'})\n    except TumblpyError:\n        # if the url given in params is not valid,\n        # Tumblr will respond with a 404 and Tumblpy will raise a TumblpyError\n\nGet a User Avatar URL *(No need for authentication for this method)*\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n.. code-block:: python\n\n    t = Tumblpy()\n    avatar = t.get_avatar_url(blog_url='tumblpy.tumblr.com', size=128)\n    print avatar['url']\n\n    # OR\n\n    avatar = t.get('avatar', blog_url='tumblpy.tumblr.com', extra_endpoints=['128'])\n    print avatar['url']\n\nCatching errors\n~~~~~~~~~~~~~~~\n\n.. code-block:: python\n\n    try:\n        t.post('user/info')\n    except TumbplyError, e:\n        print e.message\n        print 'Something bad happened :('\n\nThanks for using Tumblpy!\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaelhelmick%2Fpython-tumblpy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmichaelhelmick%2Fpython-tumblpy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaelhelmick%2Fpython-tumblpy/lists"}