### ButterCMS Python SDK: Full Integration Example Source: https://context7.com/buttercms/buttercms-python/llms.txt Demonstrates comprehensive integration with the ButterCMS Python SDK, including client initialization, fetching paginated blog posts for a homepage, retrieving a single post with its author and related category posts, and searching across posts and pages. It includes error handling for network issues and invalid authentication. ```python from butter_cms import ButterCMS from requests.exceptions import HTTPError, Timeout def initialize_blog(auth_token): """Initialize and validate ButterCMS client.""" client = ButterCMS(auth_token) try: # Validate token by making a test request client.posts.all({'page_size': 1}) return client except HTTPError: raise ValueError("Invalid ButterCMS authentication token") def get_blog_homepage(client, page=1, posts_per_page=10): """Get paginated blog posts for homepage.""" try: response = client.posts.all({ 'page': page, 'page_size': posts_per_page, 'exclude_body': 'true' }) return { 'posts': response['data'], 'meta': response.get('meta', {}) } except (HTTPError, Timeout) as e: print(f"Error fetching posts: {e}") return {'posts': [], 'meta': {}} def get_post_with_related(client, slug): """Get a post with related content.""" try: # Get the post post_response = client.posts.get(slug) post = post_response['data'] # Get author details with recent posts author_response = client.authors.get( post['author']['slug'], {'include': 'recent_posts'} ) # Get category posts category_slug = post['categories'][0]['slug'] if post['categories'] else None related_posts = [] if category_slug: category_response = client.categories.get( category_slug, {'include': 'recent_posts'} ) related_posts = category_response['data'].get('recent_posts', []) return { 'post': post, 'author': author_response['data'], 'related_posts': related_posts[:5] # Limit to 5 } except HTTPError as e: if '404' in str(e): return None raise def search_blog_content(client, query, page=1): """Search both posts and pages.""" results = { 'posts': [], 'pages': [], 'query': query } try: # Search posts post_response = client.posts.search(query, { 'page': page, 'page_size': 10 }) results['posts'] = post_response['data'] # Search pages page_response = client.pages.search(query, { 'page': page, 'page_size': 10 }) results['pages'] = page_response['data'] except (HTTPError, Timeout) as e: print(f"Search error: {e}") return results # Example usage if __name__ == "__main__": AUTH_TOKEN = "your_api_token_here" # Initialize client = initialize_blog(AUTH_TOKEN) # Get homepage posts homepage = get_blog_homepage(client, page=1, posts_per_page=10) print(f"Found {len(homepage['posts'])} posts") # Get specific post with related content post_data = get_post_with_related(client, 'example-post') if post_data: print(f"Post: {post_data['post']['title']}") print(f"Author: {post_data['author']['first_name']}") print(f"Related: {len(post_data['related_posts'])} posts") # Search content search_results = search_blog_content(client, "CMS") print(f"Search found {len(search_results['posts'])} posts and {len(search_results['pages'])} pages") ``` -------------------------------- ### Retrieve All Blog Posts (Python) Source: https://context7.com/buttercms/buttercms-python/llms.txt Shows how to fetch a list of all blog posts using the ButterCMS Python SDK. It includes examples of default retrieval, pagination, excluding body content, and accessing post details like title, slug, author, categories, tags, and summary. ```python from butter_cms import ButterCMS client = ButterCMS("your_api_token_here") # Get all posts with default settings response = client.posts.all() posts = response['data'] # Get posts with pagination and exclude body content response = client.posts.all({ 'page': 1, 'page_size': 10, 'exclude_body': 'true' }) # Access post data for post in response['data']: print(f"Title: {post['title']}") print(f"Slug: {post['slug']}") print(f"Published: {post['published']}") print(f"Author: {post['author']['first_name']} {post['author']['last_name']}") print(f"Categories: {[cat['name'] for cat in post['categories']]}") print(f"Tags: {[tag['name'] for tag in post['tags']]}") print(f"Summary: {post['summary']}") ``` -------------------------------- ### GET /posts - Retrieve All Blog Posts Source: https://context7.com/buttercms/buttercms-python/llms.txt Fetch a list of blog posts with optional filtering and pagination parameters. Returns blog posts with author information, categories, tags, and metadata. ```APIDOC ## GET /posts ### Description Retrieve a list of blog posts with optional filtering and pagination parameters. Returns comprehensive post data including author details, categories, tags, and content. ### Method GET ### Endpoint /posts ### Parameters #### Path Parameters None #### Query Parameters - **page** (integer) - Optional - Page number for pagination (default: 1) - **page_size** (integer) - Optional - Number of posts per page (default: 10) - **exclude_body** (string) - Optional - Set to 'true' to exclude post body content from response #### Request Body None ### Request Example ```python from butter_cms import ButterCMS client = ButterCMS("your_api_token_here") # Get all posts with default settings response = client.posts.all() # Get posts with pagination and exclude body content response = client.posts.all({ 'page': 1, 'page_size': 10, 'exclude_body': 'true' }) ``` ### Response #### Success Response (200) - **data** (array) - Array of blog post objects - **title** (string) - Blog post title - **slug** (string) - URL-friendly identifier - **published** (string) - Publication date - **author** (object) - Author information with first_name, last_name - **categories** (array) - Array of category objects with name - **tags** (array) - Array of tag objects with name - **summary** (string) - Post summary or excerpt #### Response Example ```json { "data": [ { "title": "Example Blog Post", "slug": "example-post", "published": "2023-01-15T10:30:00", "author": { "first_name": "John", "last_name": "Doe" }, "categories": [{"name": "Technology"}], "tags": [{"name": "Python"}], "summary": "This is a summary of the blog post..." } ] } ``` ``` -------------------------------- ### Retrieve All Posts with Pagination in Python Source: https://github.com/buttercms/buttercms-python/blob/master/README.md Shows how to fetch all blog posts from ButterCMS with specific pagination and filtering options. This example utilizes the `.all()` method on the `client.posts` object, demonstrating the use of a `params` dictionary to control `page_size`, `page` number, and `exclude_body`. ```python response = client.posts.all({'page_size': 3, 'page': 1, 'exclude_body': 'true'}) ``` -------------------------------- ### Pages API Source: https://github.com/buttercms/buttercms-python/blob/master/README.md Provides methods to retrieve, get, and search for pages. Supports optional parameters for customizing responses. ```APIDOC ## Pages API ### Description Provides methods to retrieve, get, and search for pages. Supports optional parameters for customizing responses. ### Methods #### Get all pages ##### Endpoint `/pages.all(slug, params)` ##### Parameters - `slug` (string) - Required - The slug of the page. - `params` (object) - Optional - Additional parameters to include in the response. ##### Example ```python client.pages.all('news') client.pages.all('news', {'foo': 'bar'}) ``` #### Get a specific page ##### Endpoint `/pages.get(slug, slug, params)` ##### Parameters - `slug` (string) - Required - The slug of the page. - `slug` (string) - Required - The slug of the specific page. - `params` (object) - Optional - Additional parameters to include in the response. ##### Example ```python client.pages.get('news', 'hello-world') client.pages.get('news', 'hello-world', {'foo': 'bar'}) ``` #### Search pages ##### Endpoint `/pages.search(query, params)` ##### Parameters - `query` (string) - Required - The search query. - `params` (object) - Optional - Parameters for pagination and filtering (e.g., `{'page': 1, 'page_size': 10}`). ##### Example ```python client.pages.search('enter search query', {'page': 1, 'page_size': 10}) ``` ``` -------------------------------- ### GET /posts/{slug} - Retrieve Single Blog Post Source: https://context7.com/buttercms/buttercms-python/llms.txt Get a specific blog post by its slug identifier. Returns full post content including body, SEO metadata, featured image, and complete author details. ```APIDOC ## GET /posts/{slug} ### Description Retrieve a specific blog post by its unique slug identifier. Returns complete post content including body text, SEO metadata, featured image, and detailed author information. ### Method GET ### Endpoint /posts/{slug} ### Parameters #### Path Parameters - **slug** (string) - Required - Unique URL-friendly identifier of the blog post #### Query Parameters None #### Request Body None ### Request Example ```python from butter_cms import ButterCMS client = ButterCMS("your_api_token_here") # Get a specific post by slug response = client.posts.get('example-post') ``` ### Response #### Success Response (200) - **data** (object) - Blog post object with complete details - **title** (string) - Blog post title - **body** (string) - Full post content in HTML/markdown - **seo_title** (string) - SEO-optimized title - **meta_description** (string) - SEO meta description - **featured_image** (string) - URL of featured image - **url** (string) - Public post URL - **author** (object) - Complete author object with first_name, last_name, email, bio #### Response Example ```json { "data": { "title": "Example Blog Post", "body": "
This is the full post content...
", "seo_title": "SEO Optimized Title", "meta_description": "This is the meta description for SEO", "featured_image": "https://example.com/image.jpg", "url": "/blog/example-post", "author": { "first_name": "John", "last_name": "Doe", "email": "john@example.com", "bio": "Author bio text" } } } ``` ``` -------------------------------- ### GET /pages/{page_type} - Retrieve All Pages by Type Source: https://context7.com/buttercms/buttercms-python/llms.txt Fetch all pages of a specific page type with optional parameters. Supports retrieving all pages regardless of type using wildcard '*' and locale-specific content. ```APIDOC ## GET /pages/{page_type} ### Description Retrieve all pages of a specific page type with optional parameters. Supports retrieving all pages using wildcard '*' and locale-specific content filtering. ### Method GET ### Endpoint /pages/{page_type} ### Parameters #### Path Parameters - **page_type** (string) - Required - Type of pages to retrieve (use '*' for all pages) #### Query Parameters - **locale** (string) - Optional - Locale code for localized content (default: 'en') #### Request Body None ### Request Example ```python from butter_cms import ButterCMS client = ButterCMS("your_api_token_here") # Get all pages of a specific type response = client.pages.all('news') # Get all pages regardless of type response = client.pages.all('*') # Get pages with custom parameters response = client.pages.all('landing-page', {'locale': 'en'}) ``` ### Response #### Success Response (200) - **data** (array) - Array of page objects - **name** (string) - Page display name - **slug** (string) - URL-friendly identifier - **page_type** (string) - Type of the page - **published** (string) - Publication date - **fields** (object) - Custom page fields including seo object with title and description #### Response Example ```json { "data": [ { "name": "Landing Page", "slug": "landing-page-with-components", "page_type": "landing-page", "published": "2023-01-15T10:30:00", "fields": { "seo": { "title": "SEO Title", "description": "SEO Description" } } } ] } ``` ``` -------------------------------- ### GET /pages/{page_type}/{slug} - Retrieve Single Page Source: https://context7.com/buttercms/buttercms-python/llms.txt Get a specific page by page type and slug identifier. Returns complete page content including all custom fields and component-based layouts. ```APIDOC ## GET /pages/{page_type}/{slug} ### Description Retrieve a specific page by page type and unique slug identifier. Returns complete page content including all custom fields and component-based layouts. ### Method GET ### Endpoint /pages/{page_type}/{slug} ### Parameters #### Path Parameters - **page_type** (string) - Required - Type of the page - **slug** (string) - Required - Unique URL-friendly identifier of the page #### Query Parameters None #### Request Body None ### Request Example ```python from butter_cms import ButterCMS client = ButterCMS("your_api_token_here") # Get a specific page response = client.pages.get('landing-page', 'landing-page-with-components') ``` ### Response #### Success Response (200) - **data** (object) - Page object with complete details - **name** (string) - Page display name - **page_type** (string) - Type of the page - **slug** (string) - URL-friendly identifier - **fields** (object) - Complete custom fields object with all page components #### Response Example ```json { "data": { "name": "Landing Page with Components", "page_type": "landing-page", "slug": "landing-page-with-components", "fields": { "hero_section": { "title": "Welcome to Our Site", "subtitle": "The best experience awaits" }, "content_blocks": [ { "type": "text", "content": "Important information here" } ] } } } ``` ``` -------------------------------- ### Retrieve a Specific Author by Slug in Python Source: https://github.com/buttercms/buttercms-python/blob/master/README.md Demonstrates how to get details for a specific author using their slug. The `.get()` method on `client.authors` accepts the author's slug and can optionally include recent posts via the `params` dictionary. ```python client.authors.get('jennifer-smith') ``` ```python client.authors.get('jennifer-smith', {'include':'recent_posts'}) ``` -------------------------------- ### Retrieve Single Category by Slug using ButterCMS Python SDK Source: https://context7.com/buttercms/buttercms-python/llms.txt Shows how to get a specific category by its slug using the ButterCMS Python SDK, with an option to include recent posts. Requires an API token. ```python from butter_cms import ButterCMS client = ButterCMS("your_api_token_here") # Get category with posts response = client.categories.get('product-updates', {'include': 'recent_posts'}) category = response['data'] print(f"Category: {category['name']}") print(f"Recent posts in {category['name']}:") for post in category['recent_posts']: print(f"{post['published']}: {post['title']}") print(f" URL: {post['url']}") print(f" Summary: {post['summary']}") ``` -------------------------------- ### Client Initialization Source: https://context7.com/buttercms/buttercms-python/llms.txt Initialize the ButterCMS client with API authentication token to access all available endpoints and features. ```APIDOC ## Client Initialization ### Description Initialize the ButterCMS client with your API authentication token to access all available endpoints and features. ### Method Client initialization ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **auth_token** (string) - Required - API authentication token from ButterCMS dashboard ### Request Example ```python from butter_cms import ButterCMS # Initialize with your auth token auth_token = "your_api_token_here" client = ButterCMS(auth_token) # The client provides access to all API endpoints # client.posts - Blog posts API # client.pages - Pages API # client.authors - Authors API # client.categories - Categories API # client.tags - Tags API # client.content_fields - Collections API # client.feeds - RSS/Atom/Sitemap feeds ``` ### Response #### Success Response (200) - **client** (object) - Initialized ButterCMS client instance #### Response Example ```json { "client": "ButterCMS instance with access to all endpoints" } ``` ``` -------------------------------- ### Initialize ButterCMS Client (Python) Source: https://context7.com/buttercms/buttercms-python/llms.txt Demonstrates how to initialize the ButterCMS client using your API authentication token. This client object is then used to access various API endpoints for managing content. ```python from butter_cms import ButterCMS # Initialize with your auth token auth_token = "your_api_token_here" client = ButterCMS(auth_token) # The client provides access to all API endpoints # client.posts - Blog posts API # client.pages - Pages API # client.authors - Authors API # client.categories - Categories API # client.tags - Tags API # client.content_fields - Collections API # client.feeds - RSS/Atom/Sitemap feeds ``` -------------------------------- ### Search Pages using ButterCMS Python SDK Source: https://context7.com/buttercms/buttercms-python/llms.txt Demonstrates how to search for pages using the ButterCMS Python SDK. Requires an API token and allows specifying search query, page number, and page size. ```python from butter_cms import ButterCMS client = ButterCMS("your_api_token_here") # Search pages response = client.pages.search('sample landing page', { 'page': 1, 'page_size': 10 }) # Process results for page in response['data']: print(f"Found: {page['name']} ({page['slug']})") print(f"Type: {page['page_type']}") print(f"Updated: {page['updated']}") ``` -------------------------------- ### Search Blog Posts (Python) Source: https://context7.com/buttercms/buttercms-python/llms.txt Explains how to search for blog posts using a query string with the ButterCMS Python SDK. It shows how to paginate search results and access post details including title, relevance rank, summary, and body content. ```python from butter_cms import ButterCMS client = ButterCMS("your_api_token_here") # Search for posts query = "example blog post" response = client.posts.search(query, {'page': 1, 'page_size': 10}) # Process search results for post in response['data']: print(f"Title: {post['title']}") print(f"Rank: {post['rank']}") # Search relevance score print(f"Excerpt: {post['summary']}") # Check if query appears in content if query in response['data'][0]['body']: print("Query found in post body") ``` -------------------------------- ### Retrieve All Tags with ButterCMS Python SDK Source: https://context7.com/buttercms/buttercms-python/llms.txt Demonstrates fetching all tags using the ButterCMS Python SDK. Optionally includes posts associated with each tag. Requires an API token. ```python from butter_cms import ButterCMS client = ButterCMS("your_api_token_here") # Get all tags response = client.tags.all() tags = response['data'] # Get tags with recent posts response = client.tags.all({'include': 'recent_posts'}) for tag in response['data']: print(f"Tag: {tag['name']}") print(f"Slug: {tag['slug']}") if 'recent_posts' in tag: print(f"Tagged posts: {len(tag['recent_posts'])}") ``` -------------------------------- ### Initialize ButterCMS Client in Python Source: https://github.com/buttercms/buttercms-python/blob/master/README.md Demonstrates how to initialize the ButterCMS client using an authorization token. This is the first step to interact with the ButterCMS API using the Python library. The client object is then used to make subsequent API calls. ```python from butter_cms import ButterCMS auth_token = "XXXXXXXXXXXXXXXXXXX" client = ButterCMS(auth_token) ``` -------------------------------- ### Search Blog Posts by Query in Python Source: https://github.com/buttercms/buttercms-python/blob/master/README.md Demonstrates how to search for blog posts based on a query string, with options for pagination. The `.search()` method on `client.posts` accepts the search query and a `params` dictionary for controlling `page` and `page_size`. ```python client.posts.search('query', {'page': 1, 'page_size': 10}) ``` -------------------------------- ### Retrieve All Categories with ButterCMS Python SDK Source: https://context7.com/buttercms/buttercms-python/llms.txt Illustrates fetching all blog post categories using the ButterCMS Python SDK. Optionally includes recent posts for each category. Requires an API token. ```python from butter_cms import ButterCMS client = ButterCMS("your_api_token_here") # Get all categories response = client.categories.all() categories = response['data'] # Get categories with recent posts response = client.categories.all({'include': 'recent_posts'}) for category in response['data']: print(f"Category: {category['name']}") print(f"Slug: {category['slug']}") if 'recent_posts' in category: print(f"Posts in this category: {len(category['recent_posts'])}") for post in category['recent_posts']: print(f" - {post['title']}") ``` -------------------------------- ### Blog Engine - Feeds API Source: https://github.com/buttercms/buttercms-python/blob/master/README.md Provides methods to generate RSS, Atom, and Sitemap feeds for the blog. ```APIDOC ## Blog Engine - Feeds API ### Description Provides methods to generate RSS, Atom, and Sitemap feeds for the blog. ### Methods #### Get RSS feed ##### Endpoint `/feeds.get('rss')` ##### Example ```python client.feeds.get('rss') ``` #### Get Atom feed ##### Endpoint `/feeds.get('atom')` ##### Example ```python client.feeds.get('atom') ``` #### Get Sitemap feed ##### Endpoint `/feeds.get('sitemap')` ##### Example ```python client.feeds.get('sitemap') ``` ``` -------------------------------- ### Search Pages by Query in Python Source: https://github.com/buttercms/buttercms-python/blob/master/README.md Demonstrates how to search for pages based on a query string, with pagination options. The `.search()` method on `client.pages` takes the search query and a `params` dictionary for controlling `page` and `page_size`. ```python client.pages.search('enter search query', {'page': 1, 'page_size': 10}) ``` -------------------------------- ### Retrieve Single Blog Post (Python) Source: https://context7.com/buttercms/buttercms-python/llms.txt Illustrates how to retrieve a specific blog post by its unique slug using the ButterCMS Python SDK. It demonstrates accessing the full post content, SEO details, featured image, URL, and author information. ```python from butter_cms import ButterCMS client = ButterCMS("your_api_token_here") # Get a specific post by slug response = client.posts.get('example-post') post = response['data'] # Access full post content print(f"Title: {post['title']}") print(f"Body: {post['body']}") print(f"SEO Title: {post['seo_title']}") print(f"Meta Description: {post['meta_description']}") print(f"Featured Image: {post['featured_image']}") print(f"URL: {post['url']}") # Access author details author = post['author'] print(f"Author: {author['first_name']} {author['last_name']}") print(f"Email: {author['email']}") print(f"Bio: {author['bio']}") ``` -------------------------------- ### Run Unit Tests in Python Source: https://github.com/buttercms/buttercms-python/blob/master/README.md Provides the command to execute the unit tests for the buttercms-python library. This is useful for verifying the library's functionality and ensuring code integrity. ```python python -m unittest butter_cms/unit_tests.py ``` -------------------------------- ### Retrieve Single Page (Python) Source: https://context7.com/buttercms/buttercms-python/llms.txt Shows how to fetch a specific dynamic page by its type and slug using the ButterCMS Python SDK. It demonstrates accessing basic page information like name, type, and slug. ```python from butter_cms import ButterCMS client = ButterCMS("your_api_token_here") # Get a specific page response = client.pages.get('landing-page', 'landing-page-with-components') page = response['data'] print(f"Page Name: {page['name']}") print(f"Page Type: {page['page_type']}") ``` -------------------------------- ### Blog Engine - Posts API Source: https://github.com/buttercms/buttercms-python/blob/master/README.md Manages blog posts, including fetching all posts, a single post by slug, and searching posts. ```APIDOC ## Blog Engine - Posts API ### Description Manages blog posts, including fetching all posts, a single post by slug, and searching posts. ### Methods #### Get all posts ##### Endpoint `/posts.all(params)` ##### Parameters - `params` (object) - Optional - Parameters for pagination, filtering, and excluding content (e.g., `{'page_size': 3, 'page': 1, 'exclude_body': 'true'}`). ##### Example ```python client.posts.all({'page_size': 3, 'page': 1, 'exclude_body': 'true'}) ``` #### Get a specific post ##### Endpoint `/posts.get(slug)` ##### Parameters - `slug` (string) - Required - The slug of the post. ##### Example ```python client.posts.get('hello-world') ``` #### Search posts ##### Endpoint `/posts.search(query, params)` ##### Parameters - `query` (string) - Required - The search query. - `params` (object) - Optional - Parameters for pagination and filtering (e.g., `{'page': 1, 'page_size': 10}`). ##### Example ```python client.posts.search('query', {'page': 1, 'page_size': 10}) ``` ``` -------------------------------- ### SEARCH /posts - Search Blog Posts Source: https://context7.com/buttercms/buttercms-python/llms.txt Search for blog posts matching a query string with pagination support. Returns search results with relevance ranking and excerpts. ```APIDOC ## SEARCH /posts ### Description Search for blog posts matching a query string with pagination support. Returns search results with relevance rankings and excerpts for matching content. ### Method SEARCH ### Endpoint /posts/search ### Parameters #### Path Parameters - **query** (string) - Required - Search query string #### Query Parameters - **page** (integer) - Optional - Page number for pagination (default: 1) - **page_size** (integer) - Optional - Number of results per page (default: 10) #### Request Body None ### Request Example ```python from butter_cms import ButterCMS client = ButterCMS("your_api_token_here") # Search for posts query = "example blog post" response = client.posts.search(query, {'page': 1, 'page_size': 10}) ``` ### Response #### Success Response (200) - **data** (array) - Array of matching blog posts - **title** (string) - Blog post title - **rank** (number) - Search relevance score - **summary** (string) - Post summary or excerpt #### Response Example ```json { "data": [ { "title": "Matching Blog Post", "rank": 0.95, "summary": "This post contains the search terms..." } ] } ``` ``` -------------------------------- ### Retrieve All Authors with ButterCMS Python SDK Source: https://context7.com/buttercms/buttercms-python/llms.txt Shows how to fetch all authors using the ButterCMS Python SDK. Optionally includes recent posts for each author. Requires an API token. ```python from butter_cms import ButterCMS client = ButterCMS("your_api_token_here") # Get all authors response = client.authors.all() authors = response['data'] # Get authors with their recent posts response = client.authors.all({'include': 'recent_posts'}) for author in response['data']: print(f"Name: {author['first_name']} {author['last_name']}") print(f"Slug: {author['slug']}") print(f"Email: {author['email']}") print(f"Bio: {author['bio']}") # Access recent posts if included if 'recent_posts' in author: for post in author['recent_posts']: print(f" - {post['title']}") ``` -------------------------------- ### Blog Engine - Tags API Source: https://github.com/buttercms/buttercms-python/blob/master/README.md Allows retrieval of all tags or a specific tag by slug, with an option to include related posts. ```APIDOC ## Blog Engine - Tags API ### Description Allows retrieval of all tags or a specific tag by slug, with an option to include related posts. ### Methods #### Get all tags ##### Endpoint `/tags.all(params)` ##### Parameters - `params` (object) - Optional - Additional parameters (e.g., `{'include':'recent_posts'}`). ##### Example ```python client.tags.all() client.tags.all({'include':'recent_posts'}) ``` #### Get a specific tag ##### Endpoint `/tags.get(slug, params)` ##### Parameters - `slug` (string) - Required - The slug of the tag. - `params` (object) - Optional - Additional parameters (e.g., `{'include':'recent_posts'}`). ##### Example ```python client.tags.get('product-updates') client.tags.get('product-updates', {'include':'recent_posts'}) ``` ``` -------------------------------- ### Retrieve Atom Feed using ButterCMS Python Source: https://context7.com/buttercms/buttercms-python/llms.txt Fetches the Atom feed for blog posts in Atom 1.0 XML format. Uses ButterCMS client initialized with API token and feeds.get('atom') method. Outputs XML string in response['data'] for direct serving. Limitation: Dependent on blog post data; Atom-specific syndication features only. ```python from butter_cms import ButterCMS client = ButterCMS("your_api_token_here") # Get Atom feed response = client.feeds.get('atom') atom_xml = response['data'] # Serve the Atom feed print(atom_xml) # Atom 1.0 formatted XML ``` -------------------------------- ### Retrieve All Tags with Optional Data in Python Source: https://github.com/buttercms/buttercms-python/blob/master/README.md Demonstrates how to retrieve all tags. Similar to authors and categories, the `.all()` method on `client.tags` supports an optional `params` dictionary, such as `{'include':'recent_posts'}`, to fetch associated posts. ```python client.tags.all() ``` ```python client.tags.all({'include':'recent_posts'}) ``` -------------------------------- ### Retrieve Content Collections using ButterCMS Python Source: https://context7.com/buttercms/buttercms-python/llms.txt Fetches custom content collections by specifying keys, supporting single or multiple collections and optional locale parameters. Depends on the butter_cms library and a valid API token for client initialization. Outputs a dictionary in response['data'] with collection keys mapping to their values; prints or processes data accordingly. Limitation: API rate limits and token validity apply. ```python from butter_cms import ButterCMS client = ButterCMS("your_api_token_here") # Get single collection response = client.content_fields.get(['navigation_menu']) navigation = response['data']['navigation_menu'] # Get multiple collections response = client.content_fields.get([ 'navigation_menu', 'footer_content', 'homepage_hero' ]) # Access collection data for key, value in response['data'].items(): print(f"Collection: {key}") print(f"Data: {value}") # Get collection with locale response = client.content_fields.get(['products'], {'locale': 'en'}) products = response['data']['products'] ``` -------------------------------- ### Retrieve All Pages by Type (Python) Source: https://context7.com/buttercms/buttercms-python/llms.txt Demonstrates fetching all pages of a specific type or all pages regardless of type using the ButterCMS Python SDK. It covers using custom parameters like locale and accessing page data including name, slug, page type, and custom fields. ```python from butter_cms import ButterCMS client = ButterCMS("your_api_token_here") # Get all pages of a specific type response = client.pages.all('news') pages = response['data'] # Get all pages regardless of type response = client.pages.all('*') # Get pages with custom parameters response = client.pages.all('landing-page', {'locale': 'en'}) # Access page data for page in response['data']: print(f"Name: {page['name']}") print(f"Slug: {page['slug']}") print(f"Page Type: {page['page_type']}") print(f"Published: {page['published']}") # Access page fields fields = page['fields'] if 'seo' in fields: print(f"SEO Title: {fields['seo']['title']}") print(f"SEO Description: {fields['seo']['description']}") ``` -------------------------------- ### Blog Engine - Categories API Source: https://github.com/buttercms/buttercms-python/blob/master/README.md Enables fetching all categories or a specific category by slug. Can include posts associated with the category. ```APIDOC ## Blog Engine - Categories API ### Description Enables fetching all categories or a specific category by slug. Can include posts associated with the category. ### Methods #### Get all categories ##### Endpoint `/categories.all(params)` ##### Parameters - `params` (object) - Optional - Additional parameters (e.g., `{'include':'recent_posts'}`). ##### Example ```python client.categories.all() client.categories.all({'include':'recent_posts'}) ``` #### Get a specific category ##### Endpoint `/categories.get(slug, params)` ##### Parameters - `slug` (string) - Required - The slug of the category. - `params` (object) - Optional - Additional parameters (e.g., `{'include':'recent_posts'}`). ##### Example ```python client.categories.get('product-updates') client.categories.get('product-updates', {'include':'recent_posts'}) ``` ``` -------------------------------- ### Retrieve a Specific Tag by Slug in Python Source: https://github.com/buttercms/buttercms-python/blob/master/README.md Shows how to fetch a specific tag using its slug. The `.get()` method on `client.tags` takes the tag slug and can optionally include recent posts via the `params` argument. ```python client.tags.get('product-updates') ``` ```python client.tags.get('product-updates', {'include':'recent_posts'}) ``` -------------------------------- ### Retrieve a Specific Page by Slug in Python Source: https://github.com/buttercms/buttercms-python/blob/master/README.md Illustrates how to fetch a single page using its page type and slug. The `.get()` method on `client.pages` accepts both the page type and the page slug, along with an optional `params` dictionary. ```python client.pages.get('news', 'hello-world') ``` ```python client.pages.get('news', 'hello-world', {'foo': 'bar'}) ``` -------------------------------- ### Retrieve a Specific Post by Slug in Python Source: https://github.com/buttercms/buttercms-python/blob/master/README.md Illustrates how to retrieve a single blog post using its unique slug. The `.get()` method on the `client.posts` object is used for this purpose, requiring the post's slug as an argument. ```python client.posts.get('hello-world') ``` -------------------------------- ### Retrieve RSS Feed using ButterCMS Python Source: https://context7.com/buttercms/buttercms-python/llms.txt Fetches the RSS feed for blog posts in RSS 2.0 XML format. Initializes ButterCMS client with API token and calls feeds.get('rss'). Outputs XML string in response['data'] ready for serving. Limitation: Requires published blog posts; no customization of feed content via this method. ```python from butter_cms import ButterCMS client = ButterCMS("your_api_token_here") # Get RSS feed response = client.feeds.get('rss') rss_xml = response['data'] # The response contains RSS XML that can be served directly print(rss_xml) # RSS 2.0 formatted XML ``` -------------------------------- ### Retrieve All Categories with Optional Data in Python Source: https://github.com/buttercms/buttercms-python/blob/master/README.md Shows how to fetch all categories. The `.all()` method on `client.categories` can take an optional `params` dictionary, like `{'include':'recent_posts'}`, to include posts associated with each category. ```python client.categories.all() ``` ```python client.categories.all({'include':'recent_posts'}) ``` -------------------------------- ### Retrieve Sitemap using ButterCMS Python Source: https://context7.com/buttercms/buttercms-python/llms.txt Generates an XML sitemap for content pages suitable for SEO. Requires ButterCMS client with API token and calls feeds.get('sitemap'). Returns XML string in response['data']. Limitation: Includes only ButterCMS-managed pages; integrate with other site sections manually. ```python from butter_cms import ButterCMS client = ButterCMS("your_api_token_here") # Get sitemap response = client.feeds.get('sitemap') sitemap_xml = response['data'] # Use for SEO purposes print(sitemap_xml) # Sitemap XML format ``` -------------------------------- ### Retrieve All Authors with Optional Data in Python Source: https://github.com/buttercms/buttercms-python/blob/master/README.md Illustrates fetching a list of all authors. The `.all()` method on `client.authors` can accept an optional `params` dictionary, such as `{'include':'recent_posts'}`, to enrich the response with each author's recent posts. ```python client.authors.all() ``` ```python client.authors.all({'include':'recent_posts'}) ``` -------------------------------- ### Retrieve All Pages of a Specific Type in Python Source: https://github.com/buttercms/buttercms-python/blob/master/README.md Shows how to retrieve all pages of a given page type, with an option to include additional parameters. The `.all()` method on `client.pages` takes the page type and an optional `params` dictionary. ```python client.pages.all('news') ``` ```python client.pages.all('news', {'foo': 'bar'}) ``` -------------------------------- ### Blog Engine - Authors API Source: https://github.com/buttercms/buttercms-python/blob/master/README.md Provides methods to retrieve all authors or a specific author by slug. Supports including author's recent posts. ```APIDOC ## Blog Engine - Authors API ### Description Provides methods to retrieve all authors or a specific author by slug. Supports including author's recent posts. ### Methods #### Get all authors ##### Endpoint `/authors.all(params)` ##### Parameters - `params` (object) - Optional - Additional parameters (e.g., `{'include':'recent_posts'}`). ##### Example ```python client.authors.all() client.authors.all({'include':'recent_posts'}) ``` #### Get a specific author ##### Endpoint `/authors.get(slug, params)` ##### Parameters - `slug` (string) - Required - The slug of the author. - `params` (object) - Optional - Additional parameters (e.g., `{'include':'recent_posts'}`). ##### Example ```python client.authors.get('jennifer-smith') client.authors.get('jennifer-smith', {'include':'recent_posts'}) ``` ``` -------------------------------- ### Retrieve a Specific Category by Slug in Python Source: https://github.com/buttercms/buttercms-python/blob/master/README.md Illustrates fetching a single category by its slug. The `.get()` method on `client.categories` accepts the category slug and can optionally include recent posts using the `params` parameter. ```python client.categories.get('product-updates') ``` ```python client.categories.get('product-updates', {'include':'recent_posts'}) ``` -------------------------------- ### Retrieve Collection Content Fields in Python Source: https://github.com/buttercms/buttercms-python/blob/master/README.md Shows how to retrieve content fields for a specific collection using its key. The `.get()` method on `client.content_fields` accepts a list of collection keys and an optional `params` dictionary, such as specifying the locale. ```python client.content_fields.get(['collection_key'], {'locale': 'en'}) ``` -------------------------------- ### Handle Errors in ButterCMS Python API Source: https://context7.com/buttercms/buttercms-python/llms.txt Manages authentication, HTTP, timeout, and general exceptions when calling API methods like posts.get(). Depends on requests library for HTTPError and Timeout; wraps in try-except blocks. Inputs API calls, outputs error messages based on status like 401 for invalid token or 404 for not found. Limitation: Default timeout is 10 seconds; custom timeouts via client params. ```python from butter_cms import ButterCMS from requests.exceptions import HTTPError, Timeout client = ButterCMS("your_api_token_here") try: response = client.posts.get('my-post-slug') post = response['data'] print(f"Retrieved: {post['title']}") except HTTPError as e: # Handle 401 unauthorized, 404 not found, etc. print(f"HTTP Error: {e}") if '401' in str(e): print("Invalid authentication token") elif '404' in str(e): print("Post not found") else: print("API error occurred") except Timeout: # Handle request timeout (default 10 seconds) print("Request timed out after 10 seconds") except Exception as e: # Handle other exceptions print(f"Unexpected error: {e}") ``` -------------------------------- ### Retrieve Single Author by Slug using ButterCMS Python SDK Source: https://context7.com/buttercms/buttercms-python/llms.txt Demonstrates fetching a specific author by their slug using the ButterCMS Python SDK. Allows for optional inclusion of recent posts. Requires an API token. ```python from butter_cms import ButterCMS client = ButterCMS("your_api_token_here") # Get author without posts response = client.authors.get('jennifer-smith') author = response['data'] # Get author with recent posts response = client.authors.get('jennifer-smith', {'include': 'recent_posts'}) author = response['data'] print(f"Author: {author['first_name']} {author['last_name']}") print(f"Title: {author['title']}") print(f"Social: Twitter @{author['twitter_handle']}") print(f"LinkedIn: {author['linkedin_url']}") if 'recent_posts' in author: print("Recent posts:") for post in author['recent_posts']: print(f" {post['published']}: {post['title']}") ``` -------------------------------- ### Retrieve Specific Feed Types in Python Source: https://github.com/buttercms/buttercms-python/blob/master/README.md Illustrates how to retrieve different types of feeds (RSS, Atom, Sitemap) from ButterCMS. The `.get()` method on `client.feeds` is used, taking the feed type as a string argument. ```python client.feeds.get('rss') ``` ```python client.feeds.get('atom') ``` ```python client.feeds.get('sitemap') ``` -------------------------------- ### Retrieve Single Tag by Slug using ButterCMS Python SDK Source: https://context7.com/buttercms/buttercms-python/llms.txt Shows how to retrieve a specific tag by its slug identifier using the ButterCMS Python SDK, with an option to include recent posts. Requires an API token. ```python from butter_cms import ButterCMS client = ButterCMS("your_api_token_here") # Get tag with recent posts response = client.tags.get('product-updates', {'include': 'recent_posts'}) tag = response['data'] print(f"Tag: {tag['name']}") for post in tag['recent_posts']: print(f" - {post['title']} by {post['author']['first_name']}") ``` -------------------------------- ### Collections API Source: https://github.com/buttercms/buttercms-python/blob/master/README.md Allows retrieval of collection data with optional parameters for localization. ```APIDOC ## Collections API ### Description Allows retrieval of collection data with optional parameters for localization. ### Method #### Get collection data ##### Endpoint `/content_fields.get(collection_keys, params)` ##### Parameters - `collection_keys` (array of strings) - Required - The keys of the collections to retrieve. - `params` (object) - Optional - Additional parameters, such as locale settings (e.g., `{'locale': 'en'}`). ##### Example ```python client.content_fields.get(['collection_key'], {'locale': 'en'}) ``` ``` -------------------------------- ### Access Component-Based Body Content in Python Source: https://context7.com/buttercms/buttercms-python/llms.txt Iterates through a 'body' component in a page's fields to access and print data based on component type (hero, two_column_with_image, features). Handles nested structures for features. ```python for component in page['fields']['body']: comp_type = component['type'] comp_fields = component['fields'] if comp_type == 'hero': print(f"Hero Headline: {comp_fields['headline']}") print(f"Hero Image: {comp_fields['image']}") print(f"Button: {comp_fields['button_label']} -> {comp_fields['button_url']}") elif comp_type == 'two_column_with_image': print(f"Headline: {comp_fields['headline']}") print(f"Image Position: {comp_fields['image_position']}") elif comp_type == 'features': for feature in comp_fields['features']: print(f"Feature: {feature['headline']} - {feature['description']}") ``` -------------------------------- ### Retrieve Filtered Collections using ButterCMS Python Source: https://context7.com/buttercms/buttercms-python/llms.txt Retrieves a specific content collection with field-based filtering using department or status criteria, including locale. Requires ButterCMS client and API token; uses get_collection method with fields list and params. Outputs list of matching items in response['data'], iterable for name, role, department, bio. Limitation: Filters are exact matches; complex queries may need server-side adjustments. ```python from butter_cms import ButterCMS client = ButterCMS("your_api_token_here") # Get collection with field filters response = client.content_fields.get_collection( 'team_members', fields=[ {'department': 'engineering'}, {'status': 'active'} ], params={'locale': 'en'} ) team_members = response['data'] for member in team_members: print(f"Name: {member['name']}") print(f"Role: {member['role']}") print(f"Department: {member['department']}") print(f"Bio: {member['bio']}") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.