A Python toolkit for interacting with the Google Blogger API with simplified authentication and enhanced features.
π§ Environment Variable Support - No more manual credentials.json
management!
π Auto-generated Credentials - Automatically creates credentials from environment variables
π Full Backward Compatibility - All existing code continues to work unchanged
π Enhanced Post Features - Added labels
and is_draft
parameters
π¬ Improved User Experience - Better error messages and helpful logging
pip install bloggerkit
-
Set up Google Cloud Console:
- Go to Google Cloud Console
- Create a new project or select existing one
- Enable the Blogger API
- Go to APIs & Services β Credentials
- Create OAuth 2.0 Client ID (Desktop Application)
- Copy the Client ID and Client Secret
-
Set environment variables:
# Add to your .env file or export directly export GOOGLE_CLIENT_ID="your_client_id_here" export GOOGLE_CLIENT_SECRET="your_client_secret_here" export BLOG_ID="your_blog_id_here"
-
Use bloggerkit:
from bloggerkit.client import BloggerClient # Simple initialization - uses environment variables automatically client = BloggerClient("your_blog_id") # Create a post post = client.create_post( title="My First Post", content="<p>Hello World!</p>", labels=["python", "blogging"], is_draft=False ) print(f"β Post created: {post['url']}")
from bloggerkit.client import BloggerClient
client = BloggerClient(
blog_id="your_blog_id",
client_secrets_file="path/to/credentials.json"
)
from bloggerkit.client import BloggerClient
client = BloggerClient(
blog_id="your_blog_id",
client_id="your_client_id",
client_secret="your_client_secret"
)
posts = client.list_posts()
if posts:
for post in posts.items:
print(f"π {post.title}: {post.url}")
# Basic post
new_post = client.create_post(
title="My New Post",
content="<p>This is my new blog post content.</p>"
)
# Advanced post with labels and draft mode
draft_post = client.create_post(
title="Draft Post",
content="<p>This is a draft post.</p>",
labels=["draft", "work-in-progress"],
is_draft=True
)
post = client.get_post("POST_ID")
if post:
print(f"π Title: {post.title}")
print(f"π URL: {post.url}")
print(f"π·οΈ Labels: {post.labels}")
updated_post = client.update_post(
post_id="POST_ID",
title="Updated Title",
content="<p>Updated content goes here.</p>",
labels=["updated", "python"]
)
client.delete_post("POST_ID")
print("ποΈ Post deleted successfully!")
- First Run: Browser opens for Google OAuth authentication
- Token Storage: Creates
token.json
for future automatic authentication - Auto-refresh: Automatically refreshes expired tokens
- Seamless Experience: No manual intervention needed after initial setup
bloggerkit uses the following priority order for authentication:
- Direct Parameters (
client_id
,client_secret
) - Environment Variables (
GOOGLE_CLIENT_ID
,GOOGLE_CLIENT_SECRET
) - Credentials File (
client_secrets_file
)
BloggerClient(
blog_id: str,
client_secrets_file: str = None,
client_id: str = None,
client_secret: str = None
)
Method | Description | Parameters |
---|---|---|
list_posts() |
Get all posts | None |
create_post() |
Create new post | title , content , labels=None , is_draft=False |
get_post() |
Get specific post | post_id |
update_post() |
Update existing post | post_id , title , content , labels=None |
delete_post() |
Delete post | post_id |
No changes required! Your existing code works exactly the same:
# This still works perfectly
client = BloggerClient(blog_id, client_secrets_file)
Optional enhancement - Simplify with environment variables:
# Before (v0.6.x)
client = BloggerClient("blog_id", "credentials.json")
# After (v0.7.0) - Optional improvement
os.environ['GOOGLE_CLIENT_ID'] = 'your_id'
os.environ['GOOGLE_CLIENT_SECRET'] = 'your_secret'
client = BloggerClient("blog_id") # Much cleaner!
git clone https://github.com/StatPan/bloggerkit.git
cd bloggerkit
pip install -e .
- Python 3.10+
- Google Blogger API access
- OAuth 2.0 credentials
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
See changelog.md for detailed version history.
This project is licensed under the MIT License.
- π Documentation
- π Issues
- π¬ Discussions
Happy Blogging! ππ