SDKs overview
Software Development Kits (SDKs) and libraries for the Tumblr API facilitate programmatic interaction with the platform, allowing developers to build applications that post content, manage blogs, and retrieve user data. The Tumblr API operates on OAuth 1.0a for authentication, a standard protocol for secure API access. While OAuth 1.0a is robust, its implementation can be more involved compared to newer protocols like OAuth 2.0, as detailed in the OAuth 1.0 specification. SDKs are designed to abstract this complexity, offering language-specific methods to handle signature generation and token exchange.
These tools typically provide functionalities such as:
- Authentication flow management: Simplifying the process of obtaining user consent and exchanging tokens for API access.
- Endpoint wrappers: Providing structured methods corresponding to specific API endpoints (e.g.,
create_post,get_blog_info). - Request signing: Automating the cryptographic signing of requests required by OAuth 1.0a.
- Response parsing: Converting API responses (typically JSON) into native language objects for easier manipulation.
- Error handling: Providing mechanisms to identify and respond to API errors.
Developers choose an SDK or library based on their preferred programming language and the specific features required for their application. The maturity and maintenance status of these libraries can vary, with official SDKs generally offering more consistent support.
Official SDKs by language
Tumblr provides official SDKs for Python and PHP, designed to integrate directly with the Tumblr API v2. These SDKs are maintained by Tumblr and offer a reliable interface for common API operations. They abstract the complexities of OAuth 1.0a authentication and direct HTTP requests, allowing developers to focus on application logic. The official SDKs are documented within the broader Tumblr API v2 documentation.
| Language | Package Name | Install Command | Maturity |
|---|---|---|---|
| Python | PyTumblr |
pip install pytumblr |
Official, Maintained |
| PHP | tumblr/tumblr |
composer require tumblr/tumblr |
Official, Maintained |
Installation
Installation of the official Tumblr SDKs follows standard package management practices for their respective languages.
Python (PyTumblr)
To install the official Python SDK, PyTumblr, use pip, the Python package installer. Ensure you have Python and pip installed on your system.
pip install pytumblr
For more advanced usage or to install from source, refer to the PyTumblr GitHub repository or official documentation.
PHP (tumblr/tumblr)
For the official PHP SDK, tumblr/tumblr, Composer is used for dependency management. If you don't have Composer, you can install it by following the Composer installation guide.
composer require tumblr/tumblr
After installation, Composer will generate an autoloader file that you'll need to include in your PHP project to use the library's classes.
Quickstart example
This quickstart demonstrates how to use the official Python SDK, PyTumblr, to post a simple text blog entry. Before running this code, you will need to obtain API credentials (Consumer Key, Consumer Secret, OAuth Token, and OAuth Secret) from the Tumblr API console for your application.
import pytumblr
# Replace with your actual consumer key and secret
CONSUMER_KEY = 'YOUR_CONSUMER_KEY'
CONSUMER_SECRET = 'YOUR_CONSUMER_SECRET'
# Replace with your actual OAuth token and secret
OAUTH_TOKEN = 'YOUR_OAUTH_TOKEN'
OAUTH_SECRET = 'YOUR_OAUTH_SECRET'
# Replace with your blog name (e.g., 'yourblog.tumblr.com' -> 'yourblog')
BLOG_NAME = 'yourblogname'
# Authenticate with Tumblr API
client = pytumblr.TumblrRestClient(
CONSUMER_KEY,
CONSUMER_SECRET,
OAUTH_TOKEN,
OAUTH_SECRET
)
# Define the post content
post_type = 'text'
post_title = 'My First PyTumblr Post'
post_body = 'Hello, Tumblr from Python! This post was created using the official PyTumblr SDK.'
# Make the API call to create the post
try:
response = client.create_text(BLOG_NAME, title=post_title, body=post_body)
print("Post created successfully!")
print(response)
except Exception as e:
print(f"An error occurred: {e}")
print("Please ensure your API keys, tokens, and blog name are correct and authorized.")
This example initializes the TumblrRestClient with your application's credentials and then calls the create_text method to publish a new text post to the specified blog. The response object from the API call can be inspected for confirmation or error details. Proper error handling and credential management are critical for production applications.
Community libraries
Beyond the official SDKs, the developer community has created and maintained various libraries for integrating with the Tumblr API in other programming languages. These libraries often fill gaps for languages not officially supported or offer alternative implementations with different features or design philosophies. While community libraries can be highly functional, their maintenance status and adherence to the latest API changes may vary.
Notable community-contributed libraries include:
-
Ruby:
tumblr_client- Installation:
gem install tumblr_client - Description: A Ruby wrapper for the Tumblr API, providing an idiomatic interface for Ruby developers. It handles OAuth 1.0a authentication and API requests.
- Source: Typically found on RubyGems.org.
- Installation:
-
Node.js:
tumblr.js- Installation:
npm install tumblr.js - Description: A Node.js client library for the Tumblr API, suitable for server-side JavaScript applications. It supports various API endpoints and authentication methods.
- Source: Available via npm.
- Installation:
- Java: While a single widely-used, officially recognized Java SDK for Tumblr a is not prominent, several open-source projects exist on platforms like GitHub. Developers often either use generic HTTP client libraries (e.g., Apache HttpClient, OkHttp) to directly interact with the Tumblr API's RESTful endpoints, or utilize an OAuth 1.0a library to manage authentication signatures and then construct requests manually.
When selecting a community library, it is advisable to check its last update date, open issues, and developer activity to ensure it remains compatible with the current Tumblr API and is actively supported. Reviewing the library's documentation and examples is also crucial for successful integration.