confluence-as 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. confluence_as-1.0.0/.gitignore +131 -0
  2. confluence_as-1.0.0/LICENSE +21 -0
  3. confluence_as-1.0.0/PKG-INFO +331 -0
  4. confluence_as-1.0.0/README.md +287 -0
  5. confluence_as-1.0.0/pyproject.toml +224 -0
  6. confluence_as-1.0.0/src/confluence_as/__init__.py +330 -0
  7. confluence_as-1.0.0/src/confluence_as/adf_helper.py +577 -0
  8. confluence_as-1.0.0/src/confluence_as/autocomplete_cache.py +321 -0
  9. confluence_as-1.0.0/src/confluence_as/cli/__init__.py +5 -0
  10. confluence_as-1.0.0/src/confluence_as/cli/cli_utils.py +358 -0
  11. confluence_as-1.0.0/src/confluence_as/cli/commands/__init__.py +1 -0
  12. confluence_as-1.0.0/src/confluence_as/cli/commands/admin_cmds.py +1114 -0
  13. confluence_as-1.0.0/src/confluence_as/cli/commands/analytics_cmds.py +462 -0
  14. confluence_as-1.0.0/src/confluence_as/cli/commands/attachment_cmds.py +391 -0
  15. confluence_as-1.0.0/src/confluence_as/cli/commands/bulk_cmds.py +1023 -0
  16. confluence_as-1.0.0/src/confluence_as/cli/commands/comment_cmds.py +487 -0
  17. confluence_as-1.0.0/src/confluence_as/cli/commands/hierarchy_cmds.py +530 -0
  18. confluence_as-1.0.0/src/confluence_as/cli/commands/jira_cmds.py +794 -0
  19. confluence_as-1.0.0/src/confluence_as/cli/commands/label_cmds.py +423 -0
  20. confluence_as-1.0.0/src/confluence_as/cli/commands/ops_cmds.py +875 -0
  21. confluence_as-1.0.0/src/confluence_as/cli/commands/page_cmds.py +828 -0
  22. confluence_as-1.0.0/src/confluence_as/cli/commands/permission_cmds.py +628 -0
  23. confluence_as-1.0.0/src/confluence_as/cli/commands/property_cmds.py +460 -0
  24. confluence_as-1.0.0/src/confluence_as/cli/commands/search_cmds.py +1023 -0
  25. confluence_as-1.0.0/src/confluence_as/cli/commands/space_cmds.py +478 -0
  26. confluence_as-1.0.0/src/confluence_as/cli/commands/template_cmds.py +613 -0
  27. confluence_as-1.0.0/src/confluence_as/cli/commands/watch_cmds.py +352 -0
  28. confluence_as-1.0.0/src/confluence_as/cli/helpers.py +78 -0
  29. confluence_as-1.0.0/src/confluence_as/cli/main.py +100 -0
  30. confluence_as-1.0.0/src/confluence_as/config_manager.py +123 -0
  31. confluence_as-1.0.0/src/confluence_as/confluence_client.py +683 -0
  32. confluence_as-1.0.0/src/confluence_as/credential_manager.py +328 -0
  33. confluence_as-1.0.0/src/confluence_as/error_handler.py +303 -0
  34. confluence_as-1.0.0/src/confluence_as/formatters.py +303 -0
  35. confluence_as-1.0.0/src/confluence_as/markdown_parser.py +200 -0
  36. confluence_as-1.0.0/src/confluence_as/mock/__init__.py +45 -0
  37. confluence_as-1.0.0/src/confluence_as/mock/base.py +254 -0
  38. confluence_as-1.0.0/src/confluence_as/mock/client.py +41 -0
  39. confluence_as-1.0.0/src/confluence_as/mock/mixins/__init__.py +11 -0
  40. confluence_as-1.0.0/src/confluence_as/mock/mixins/content.py +243 -0
  41. confluence_as-1.0.0/src/confluence_as/mock/mixins/page.py +268 -0
  42. confluence_as-1.0.0/src/confluence_as/mock/mixins/space.py +106 -0
  43. confluence_as-1.0.0/src/confluence_as/space_context.py +447 -0
  44. confluence_as-1.0.0/src/confluence_as/validators.py +444 -0
  45. confluence_as-1.0.0/src/confluence_as/xhtml_helper.py +529 -0
@@ -0,0 +1,131 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ *.egg-info/
24
+ .installed.cfg
25
+ *.egg
26
+
27
+ # PyInstaller
28
+ *.manifest
29
+ *.spec
30
+
31
+ # Installer logs
32
+ pip-log.txt
33
+ pip-delete-this-directory.txt
34
+
35
+ # Unit test / coverage reports
36
+ htmlcov/
37
+ .tox/
38
+ .nox/
39
+ .coverage
40
+ .coverage.*
41
+ .cache
42
+ nosetests.xml
43
+ coverage.xml
44
+ *.cover
45
+ *.py,cover
46
+ .hypothesis/
47
+ .pytest_cache/
48
+
49
+ # Translations
50
+ *.mo
51
+ *.pot
52
+
53
+ # Django stuff:
54
+ *.log
55
+ local_settings.py
56
+ db.sqlite3
57
+ db.sqlite3-journal
58
+
59
+ # Flask stuff:
60
+ instance/
61
+ .webassets-cache
62
+
63
+ # Scrapy stuff:
64
+ .scrapy
65
+
66
+ # Sphinx documentation
67
+ docs/_build/
68
+
69
+ # PyBuilder
70
+ target/
71
+
72
+ # Jupyter Notebook
73
+ .ipynb_checkpoints
74
+
75
+ # IPython
76
+ profile_default/
77
+ ipython_config.py
78
+
79
+ # pyenv
80
+ .python-version
81
+
82
+ # pipenv
83
+ Pipfile.lock
84
+
85
+ # PEP 582
86
+ __pypackages__/
87
+
88
+ # Celery stuff
89
+ celerybeat-schedule
90
+ celerybeat.pid
91
+
92
+ # SageMath parsed files
93
+ *.sage.py
94
+
95
+ # Environments
96
+ .env
97
+ .venv
98
+ env/
99
+ venv/
100
+ ENV/
101
+ env.bak/
102
+ venv.bak/
103
+
104
+ # Spyder project settings
105
+ .spyderproject
106
+ .spyproject
107
+
108
+ # Rope project settings
109
+ .ropeproject
110
+
111
+ # mkdocs documentation
112
+ /site
113
+
114
+ # mypy
115
+ .mypy_cache/
116
+ .dmypy.json
117
+ dmypy.json
118
+
119
+ # Pyre type checker
120
+ .pyre/
121
+
122
+ # IDE
123
+ .idea/
124
+ .vscode/
125
+ *.swp
126
+ *.swo
127
+ *~
128
+
129
+ # OS
130
+ .DS_Store
131
+ Thumbs.db
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 grandcamel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,331 @@
1
+ Metadata-Version: 2.4
2
+ Name: confluence-as
3
+ Version: 1.0.0
4
+ Summary: Python library for Confluence Cloud REST API - shared utilities for Confluence automation
5
+ Project-URL: Homepage, https://github.com/grandcamel/confluence-as
6
+ Project-URL: Documentation, https://github.com/grandcamel/confluence-as#readme
7
+ Project-URL: Repository, https://github.com/grandcamel/confluence-as
8
+ Project-URL: Issues, https://github.com/grandcamel/confluence-as/issues
9
+ Project-URL: Changelog, https://github.com/grandcamel/confluence-as/blob/main/CHANGELOG.md
10
+ Author-email: grandcamel <noreply@github.com>
11
+ License-Expression: MIT
12
+ License-File: LICENSE
13
+ Keywords: api,atlassian,automation,cloud,confluence,documentation,rest
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.9
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Programming Language :: Python :: 3.13
24
+ Classifier: Topic :: Documentation
25
+ Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
26
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
27
+ Requires-Python: >=3.9
28
+ Requires-Dist: assistant-skills-lib>=1.0.0
29
+ Requires-Dist: click>=8.0.0
30
+ Requires-Dist: requests>=2.28.0
31
+ Provides-Extra: dev
32
+ Requires-Dist: bandit>=1.7.0; extra == 'dev'
33
+ Requires-Dist: click>=8.0.0; extra == 'dev'
34
+ Requires-Dist: coverage>=7.0.0; extra == 'dev'
35
+ Requires-Dist: mypy>=1.8.0; extra == 'dev'
36
+ Requires-Dist: pre-commit>=3.0.0; extra == 'dev'
37
+ Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
38
+ Requires-Dist: pytest-mock>=3.10.0; extra == 'dev'
39
+ Requires-Dist: pytest>=7.0.0; extra == 'dev'
40
+ Requires-Dist: responses>=0.23.0; extra == 'dev'
41
+ Requires-Dist: ruff>=0.4.0; extra == 'dev'
42
+ Requires-Dist: types-requests>=2.28.0; extra == 'dev'
43
+ Description-Content-Type: text/markdown
44
+
45
+ # Confluence AS
46
+
47
+ [![PyPI version](https://img.shields.io/pypi/v/confluence-as.svg)](https://pypi.org/project/confluence-as/)
48
+ [![Python versions](https://img.shields.io/pypi/pyversions/confluence-as.svg)](https://pypi.org/project/confluence-as/)
49
+ [![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
50
+
51
+ Python library for Confluence Cloud REST API - shared utilities for the [Confluence Assistant Skills](https://github.com/grandcamel/Confluence-Assistant-Skills) project.
52
+
53
+ ## Features
54
+
55
+ - **ConfluenceClient** - HTTP client with retry logic, pagination, and file uploads
56
+ - **ConfigManager** - Multi-source configuration (env vars, JSON files)
57
+ - **Error Handling** - Exception hierarchy and decorators for clean error handling
58
+ - **Validators** - Input validation for page IDs, space keys, CQL queries, etc.
59
+ - **Formatters** - Output formatting for pages, spaces, tables, JSON, CSV
60
+ - **ADF Helper** - Atlassian Document Format conversion (Markdown ↔ ADF)
61
+ - **XHTML Helper** - Legacy storage format conversion
62
+ - **Cache** - File-based response caching with TTL
63
+
64
+ ## Installation
65
+
66
+ ```bash
67
+ pip install confluence-as
68
+ ```
69
+
70
+ > **Note:** This is the **library** package. For the CLI tool, install `confluence-assistant-skills` instead:
71
+ > ```bash
72
+ > pip install confluence-assistant-skills # CLI with 'confluence' command
73
+ > ```
74
+
75
+ ## Quick Start
76
+
77
+ ```python
78
+ from confluence_as import (
79
+ get_confluence_client,
80
+ validate_page_id,
81
+ format_page,
82
+ markdown_to_adf,
83
+ )
84
+
85
+ # Set environment variables:
86
+ # CONFLUENCE_SITE_URL=https://your-site.atlassian.net
87
+ # CONFLUENCE_EMAIL=your-email@example.com
88
+ # CONFLUENCE_API_TOKEN=your-api-token
89
+
90
+ # Get a configured client
91
+ client = get_confluence_client()
92
+
93
+ # Get a page
94
+ page_id = validate_page_id("12345")
95
+ page = client.get(f"/api/v2/pages/{page_id}")
96
+ print(format_page(page))
97
+
98
+ # Create content from Markdown
99
+ content = markdown_to_adf("# Hello\n\nThis is **bold** text.")
100
+ ```
101
+
102
+ ## Direct Client Usage
103
+
104
+ ```python
105
+ from confluence_as import ConfluenceClient
106
+
107
+ client = ConfluenceClient(
108
+ base_url="https://your-site.atlassian.net",
109
+ email="your-email@example.com",
110
+ api_token="your-api-token",
111
+ timeout=30,
112
+ max_retries=3,
113
+ )
114
+
115
+ # GET request
116
+ page = client.get("/api/v2/pages/12345")
117
+
118
+ # POST request
119
+ new_page = client.post("/api/v2/pages", json_data={
120
+ "spaceId": "123456",
121
+ "title": "New Page",
122
+ "body": {"representation": "atlas_doc_format", "value": "..."}
123
+ })
124
+
125
+ # Pagination
126
+ for page in client.paginate("/api/v2/pages", params={"space-id": "123456"}):
127
+ print(page["title"])
128
+
129
+ # File upload
130
+ result = client.upload_file(
131
+ "/api/v2/attachments",
132
+ file_path="/path/to/file.pdf",
133
+ additional_data={"pageId": "12345"}
134
+ )
135
+ ```
136
+
137
+ ## Configuration
138
+
139
+ ### Environment Variables
140
+
141
+ ```bash
142
+ export CONFLUENCE_SITE_URL="https://your-site.atlassian.net"
143
+ export CONFLUENCE_EMAIL="your-email@example.com"
144
+ export CONFLUENCE_API_TOKEN="your-api-token"
145
+ ```
146
+
147
+ ## Error Handling
148
+
149
+ ```python
150
+ from confluence_as import (
151
+ handle_errors,
152
+ ConfluenceError,
153
+ AuthenticationError,
154
+ NotFoundError,
155
+ ValidationError,
156
+ )
157
+
158
+ @handle_errors
159
+ def main():
160
+ # Validation errors
161
+ page_id = validate_page_id(user_input) # Raises ValidationError if invalid
162
+
163
+ # API errors are caught and formatted
164
+ page = client.get(f"/api/v2/pages/{page_id}")
165
+
166
+ if __name__ == "__main__":
167
+ main() # Errors are caught, formatted, and exit with appropriate code
168
+ ```
169
+
170
+ ## Validators
171
+
172
+ ```python
173
+ from confluence_as import (
174
+ validate_page_id, # Numeric string validation
175
+ validate_space_key, # Space key format
176
+ validate_cql, # CQL query syntax
177
+ validate_content_type, # page, blogpost, etc.
178
+ validate_url, # URL format
179
+ validate_email, # Email format
180
+ validate_title, # Page title constraints
181
+ validate_label, # Label format
182
+ validate_limit, # Pagination limit
183
+ )
184
+
185
+ page_id = validate_page_id("12345") # Returns "12345"
186
+ space_key = validate_space_key("docs") # Returns "DOCS" (normalized)
187
+ cql = validate_cql('space = "DOCS"') # Validates syntax
188
+ ```
189
+
190
+ ## ADF Conversion
191
+
192
+ ```python
193
+ from confluence_as import (
194
+ markdown_to_adf,
195
+ adf_to_markdown,
196
+ text_to_adf,
197
+ adf_to_text,
198
+ create_heading,
199
+ create_paragraph,
200
+ create_bullet_list,
201
+ )
202
+
203
+ # Convert Markdown to ADF
204
+ adf = markdown_to_adf("""
205
+ # My Document
206
+
207
+ This is a **bold** paragraph.
208
+
209
+ - Item 1
210
+ - Item 2
211
+
212
+ ```python
213
+ print("Hello")
214
+ ```
215
+ """)
216
+
217
+ # Convert ADF back to Markdown
218
+ markdown = adf_to_markdown(adf)
219
+
220
+ # Build ADF programmatically
221
+ from confluence_as import create_adf_doc
222
+ doc = create_adf_doc([
223
+ create_heading("Title", level=1),
224
+ create_paragraph(text="Hello, World!"),
225
+ create_bullet_list(["Item 1", "Item 2", "Item 3"]),
226
+ ])
227
+ ```
228
+
229
+ ## Caching
230
+
231
+ ```python
232
+ from confluence_as import Cache, cached
233
+
234
+ # Direct cache usage
235
+ cache = Cache(default_ttl=300) # 5 minutes
236
+ cache.set("key", {"data": "value"})
237
+ value = cache.get("key")
238
+
239
+ # Decorator usage
240
+ @cached(ttl=300)
241
+ def get_page(page_id):
242
+ return client.get(f"/api/v2/pages/{page_id}")
243
+
244
+ # First call hits API, subsequent calls use cache
245
+ page = get_page("12345")
246
+ ```
247
+
248
+ ## API Reference
249
+
250
+ ### Client
251
+
252
+ - `ConfluenceClient` - HTTP client class
253
+ - `create_client()` - Factory function
254
+ - `get_confluence_client()` - Get configured client from environment variables
255
+
256
+ ### Config
257
+
258
+ - `ConfigManager` - Configuration management class
259
+
260
+ ### Errors
261
+
262
+ - `ConfluenceError` - Base exception
263
+ - `AuthenticationError` - 401 errors
264
+ - `PermissionError` - 403 errors
265
+ - `ValidationError` - 400 errors
266
+ - `NotFoundError` - 404 errors
267
+ - `RateLimitError` - 429 errors
268
+ - `ConflictError` - 409 errors
269
+ - `ServerError` - 5xx errors
270
+
271
+ ### Formatters
272
+
273
+ - `format_page()`, `format_space()`, `format_comment()`
274
+ - `format_table()` - ASCII table formatting
275
+ - `format_json()` - JSON formatting
276
+ - `export_csv()` - CSV export
277
+ - `print_success()`, `print_warning()`, `print_info()`
278
+
279
+ ### ADF Helper
280
+
281
+ - `markdown_to_adf()`, `adf_to_markdown()`
282
+ - `text_to_adf()`, `adf_to_text()`
283
+ - `create_*()` - Node creation functions
284
+ - `validate_adf()` - Validate ADF structure
285
+
286
+ ### XHTML Helper
287
+
288
+ - `xhtml_to_markdown()`, `markdown_to_xhtml()`
289
+ - `xhtml_to_adf()`, `adf_to_xhtml()`
290
+ - `validate_xhtml()` - Validate XHTML structure
291
+
292
+ ### Cache
293
+
294
+ - `Cache` - File-based cache class
295
+ - `cached()` - Caching decorator
296
+ - `get_cache()` - Get global cache instance
297
+
298
+ ## Contributing
299
+
300
+ 1. Fork the repository
301
+ 2. Create a feature branch
302
+ 3. Make changes with tests
303
+ 4. Submit a pull request
304
+
305
+ ```bash
306
+ # Install development dependencies
307
+ pip install -e ".[dev]"
308
+
309
+ # Install pre-commit hooks (recommended)
310
+ pre-commit install
311
+
312
+ # Run tests
313
+ pytest
314
+
315
+ # Run with coverage
316
+ pytest --cov=src/confluence_as
317
+
318
+ # Code quality checks (run automatically on commit with pre-commit)
319
+ ruff check src/ tests/ # Linting
320
+ ruff format src/ tests/ # Formatting
321
+ mypy src/ # Type checking
322
+ bandit -r src/ -q # Security scanning
323
+ ```
324
+
325
+ ## License
326
+
327
+ MIT License - see [LICENSE](LICENSE) for details.
328
+
329
+ ## Related Projects
330
+
331
+ - [Confluence Assistant Skills](https://github.com/grandcamel/Confluence-Assistant-Skills) - Claude Code skills for Confluence automation