Python library for Confluence Cloud REST API - shared utilities for Confluence automation
Project description
Confluence AS
Python library for Confluence Cloud REST API - shared utilities for the Confluence Assistant Skills project.
Features
- ConfluenceClient - HTTP client with retry logic, pagination, and file uploads
- ConfigManager - Multi-source configuration (env vars, JSON files)
- Error Handling - Exception hierarchy and decorators for clean error handling
- Validators - Input validation for page IDs, space keys, CQL queries, etc.
- Formatters - Output formatting for pages, spaces, tables, JSON, CSV
- ADF Helper - Atlassian Document Format conversion (Markdown ↔ ADF)
- XHTML Helper - Legacy storage format conversion
- Cache - File-based response caching with TTL
Installation
pip install confluence-as
Note: This is the library package. For the CLI tool, install
confluence-assistant-skillsinstead:pip install confluence-assistant-skills # CLI with 'confluence' command
Quick Start
from confluence_as import (
get_confluence_client,
validate_page_id,
format_page,
markdown_to_adf,
)
# Set environment variables:
# CONFLUENCE_SITE_URL=https://your-site.atlassian.net
# CONFLUENCE_EMAIL=your-email@example.com
# CONFLUENCE_API_TOKEN=your-api-token
# Get a configured client
client = get_confluence_client()
# Get a page
page_id = validate_page_id("12345")
page = client.get(f"/api/v2/pages/{page_id}")
print(format_page(page))
# Create content from Markdown
content = markdown_to_adf("# Hello\n\nThis is **bold** text.")
Direct Client Usage
from confluence_as import ConfluenceClient
client = ConfluenceClient(
base_url="https://your-site.atlassian.net",
email="your-email@example.com",
api_token="your-api-token",
timeout=30,
max_retries=3,
)
# GET request
page = client.get("/api/v2/pages/12345")
# POST request
new_page = client.post("/api/v2/pages", json_data={
"spaceId": "123456",
"title": "New Page",
"body": {"representation": "atlas_doc_format", "value": "..."}
})
# Pagination
for page in client.paginate("/api/v2/pages", params={"space-id": "123456"}):
print(page["title"])
# File upload
result = client.upload_file(
"/api/v2/attachments",
file_path="/path/to/file.pdf",
additional_data={"pageId": "12345"}
)
Configuration
Environment Variables
export CONFLUENCE_SITE_URL="https://your-site.atlassian.net"
export CONFLUENCE_EMAIL="your-email@example.com"
export CONFLUENCE_API_TOKEN="your-api-token"
Error Handling
from confluence_as import (
handle_errors,
ConfluenceError,
AuthenticationError,
NotFoundError,
ValidationError,
)
@handle_errors
def main():
# Validation errors
page_id = validate_page_id(user_input) # Raises ValidationError if invalid
# API errors are caught and formatted
page = client.get(f"/api/v2/pages/{page_id}")
if __name__ == "__main__":
main() # Errors are caught, formatted, and exit with appropriate code
Validators
from confluence_as import (
validate_page_id, # Numeric string validation
validate_space_key, # Space key format
validate_cql, # CQL query syntax
validate_content_type, # page, blogpost, etc.
validate_url, # URL format
validate_email, # Email format
validate_title, # Page title constraints
validate_label, # Label format
validate_limit, # Pagination limit
)
page_id = validate_page_id("12345") # Returns "12345"
space_key = validate_space_key("docs") # Returns "DOCS" (normalized)
cql = validate_cql('space = "DOCS"') # Validates syntax
ADF Conversion
from confluence_as import (
markdown_to_adf,
adf_to_markdown,
text_to_adf,
adf_to_text,
create_heading,
create_paragraph,
create_bullet_list,
)
# Convert Markdown to ADF
adf = markdown_to_adf("""
# My Document
This is a **bold** paragraph.
- Item 1
- Item 2
```python
print("Hello")
""")
Convert ADF back to Markdown
markdown = adf_to_markdown(adf)
Build ADF programmatically
from confluence_as import create_adf_doc doc = create_adf_doc([ create_heading("Title", level=1), create_paragraph(text="Hello, World!"), create_bullet_list(["Item 1", "Item 2", "Item 3"]), ])
## Caching
```python
from confluence_as import Cache, cached
# Direct cache usage
cache = Cache(default_ttl=300) # 5 minutes
cache.set("key", {"data": "value"})
value = cache.get("key")
# Decorator usage
@cached(ttl=300)
def get_page(page_id):
return client.get(f"/api/v2/pages/{page_id}")
# First call hits API, subsequent calls use cache
page = get_page("12345")
API Reference
Client
ConfluenceClient- HTTP client classcreate_client()- Factory functionget_confluence_client()- Get configured client from environment variables
Config
ConfigManager- Configuration management class
Errors
ConfluenceError- Base exceptionAuthenticationError- 401 errorsPermissionError- 403 errorsValidationError- 400 errorsNotFoundError- 404 errorsRateLimitError- 429 errorsConflictError- 409 errorsServerError- 5xx errors
Formatters
format_page(),format_space(),format_comment()format_table()- ASCII table formattingformat_json()- JSON formattingexport_csv()- CSV exportprint_success(),print_warning(),print_info()
ADF Helper
markdown_to_adf(),adf_to_markdown()text_to_adf(),adf_to_text()create_*()- Node creation functionsvalidate_adf()- Validate ADF structure
XHTML Helper
xhtml_to_markdown(),markdown_to_xhtml()xhtml_to_adf(),adf_to_xhtml()validate_xhtml()- Validate XHTML structure
Cache
Cache- File-based cache classcached()- Caching decoratorget_cache()- Get global cache instance
Contributing
- Fork the repository
- Create a feature branch
- Make changes with tests
- Submit a pull request
# Install development dependencies
pip install -e ".[dev]"
# Install pre-commit hooks (recommended)
pre-commit install
# Run tests
pytest
# Run with coverage
pytest --cov=src/confluence_as
# Code quality checks (run automatically on commit with pre-commit)
ruff check src/ tests/ # Linting
ruff format src/ tests/ # Formatting
mypy src/ # Type checking
bandit -r src/ -q # Security scanning
License
MIT License - see LICENSE for details.
Related Projects
- Confluence Assistant Skills - Claude Code skills for Confluence automation
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file confluence_as-1.1.0.tar.gz.
File metadata
- Download URL: confluence_as-1.1.0.tar.gz
- Upload date:
- Size: 97.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ee38db4e1c5449f7a1f661241ab3b403fbfcc754d86f4288bf316da5fc8c56d
|
|
| MD5 |
31f7612753ac649d3cdb91aee6e23121
|
|
| BLAKE2b-256 |
4974f518e07f410533cd8d2db6b6a3ca430abbddacb70ff570ca27ae7fcb0e32
|
Provenance
The following attestation bundles were made for confluence_as-1.1.0.tar.gz:
Publisher:
publish.yml on grandcamel/confluence-as
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
confluence_as-1.1.0.tar.gz -
Subject digest:
6ee38db4e1c5449f7a1f661241ab3b403fbfcc754d86f4288bf316da5fc8c56d - Sigstore transparency entry: 885894821
- Sigstore integration time:
-
Permalink:
grandcamel/confluence-as@517ed972576dcff3e2f81768e5504870090391c1 -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/grandcamel
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@517ed972576dcff3e2f81768e5504870090391c1 -
Trigger Event:
release
-
Statement type:
File details
Details for the file confluence_as-1.1.0-py3-none-any.whl.
File metadata
- Download URL: confluence_as-1.1.0-py3-none-any.whl
- Upload date:
- Size: 122.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2fbcd2c49dc636c53547082e62fd72fe959d64760d1a16a746025c264d14d7ed
|
|
| MD5 |
605f24cd790d589800c7b9df7b74d703
|
|
| BLAKE2b-256 |
f0dfc5b895def1168bd0b206e58fb2b456e66bf91ba86dbee5b63aa0b0232497
|
Provenance
The following attestation bundles were made for confluence_as-1.1.0-py3-none-any.whl:
Publisher:
publish.yml on grandcamel/confluence-as
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
confluence_as-1.1.0-py3-none-any.whl -
Subject digest:
2fbcd2c49dc636c53547082e62fd72fe959d64760d1a16a746025c264d14d7ed - Sigstore transparency entry: 885894871
- Sigstore integration time:
-
Permalink:
grandcamel/confluence-as@517ed972576dcff3e2f81768e5504870090391c1 -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/grandcamel
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@517ed972576dcff3e2f81768e5504870090391c1 -
Trigger Event:
release
-
Statement type: