fastapi-docshield 0.1.0__tar.gz → 0.2.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 (26) hide show
  1. {fastapi_docshield-0.1.0 → fastapi_docshield-0.2.0}/PKG-INFO +163 -2
  2. fastapi_docshield-0.2.0/README.md +249 -0
  3. {fastapi_docshield-0.1.0 → fastapi_docshield-0.2.0}/fastapi_docshield/__init__.py +1 -1
  4. fastapi_docshield-0.2.0/fastapi_docshield/docshield.py +425 -0
  5. fastapi_docshield-0.2.0/fastapi_docshield/static/redoc/redoc.standalone.js +1782 -0
  6. fastapi_docshield-0.2.0/fastapi_docshield/static/swagger/swagger-ui-bundle.js +2 -0
  7. fastapi_docshield-0.2.0/fastapi_docshield/static/swagger/swagger-ui.css +3 -0
  8. fastapi_docshield-0.2.0/fastapi_docshield/static_handler.py +200 -0
  9. {fastapi_docshield-0.1.0 → fastapi_docshield-0.2.0}/pyproject.toml +10 -1
  10. fastapi_docshield-0.1.0/.github/workflows/publish-to-pypi.yml +0 -31
  11. fastapi_docshield-0.1.0/.github/workflows/python-tests.yml +0 -60
  12. fastapi_docshield-0.1.0/README.md +0 -88
  13. fastapi_docshield-0.1.0/conftest.py +0 -13
  14. fastapi_docshield-0.1.0/demo.py +0 -87
  15. fastapi_docshield-0.1.0/examples/advanced_example.py +0 -76
  16. fastapi_docshield-0.1.0/examples/basic_example.py +0 -38
  17. fastapi_docshield-0.1.0/examples/manual_test.py +0 -38
  18. fastapi_docshield-0.1.0/fastapi_docshield/docshield.py +0 -187
  19. fastapi_docshield-0.1.0/pytest.ini +0 -20
  20. fastapi_docshield-0.1.0/setup.py +0 -5
  21. fastapi_docshield-0.1.0/tests/__init__.py +0 -0
  22. fastapi_docshield-0.1.0/tests/test_docshield.py +0 -172
  23. fastapi_docshield-0.1.0/tests/test_integration.py +0 -81
  24. fastapi_docshield-0.1.0/uv.lock +0 -1523
  25. {fastapi_docshield-0.1.0 → fastapi_docshield-0.2.0}/.gitignore +0 -0
  26. {fastapi_docshield-0.1.0 → fastapi_docshield-0.2.0}/LICENSE +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fastapi-docshield
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Summary: A simple FastAPI integration to protect documentation endpoints with authentication
5
5
  Project-URL: Homepage, https://github.com/georgekhananaev/fastapi-docshield
6
6
  Project-URL: Bug Tracker, https://github.com/georgekhananaev/fastapi-docshield/issues
@@ -92,6 +92,8 @@ pip install -e .
92
92
 
93
93
  ## Quick Usage
94
94
 
95
+ ### Single User
96
+
95
97
  ```python
96
98
  from fastapi import FastAPI
97
99
  from fastapi_docshield import DocShield
@@ -102,13 +104,145 @@ app = FastAPI()
102
104
  def read_root():
103
105
  return {"Hello": "World"}
104
106
 
105
- # Add protection to docs
107
+ # Add protection to docs with a single user
106
108
  DocShield(
107
109
  app=app,
108
110
  credentials={"admin": "password123"}
109
111
  )
110
112
  ```
111
113
 
114
+ ### Multiple Users
115
+
116
+ ```python
117
+ from fastapi import FastAPI
118
+ from fastapi_docshield import DocShield
119
+
120
+ app = FastAPI()
121
+
122
+ @app.get("/")
123
+ def read_root():
124
+ return {"Hello": "World"}
125
+
126
+ # Add protection to docs with multiple users
127
+ DocShield(
128
+ app=app,
129
+ credentials={
130
+ "admin": "admin_password",
131
+ "developer": "dev_password",
132
+ "viewer": "viewer_password"
133
+ }
134
+ )
135
+ ```
136
+
137
+ ### CDN Fallback Mode (Default)
138
+
139
+ ```python
140
+ from fastapi import FastAPI
141
+ from fastapi_docshield import DocShield
142
+
143
+ app = FastAPI()
144
+
145
+ # Default mode: Use CDN with automatic fallback to local files
146
+ DocShield(
147
+ app=app,
148
+ credentials={"admin": "password123"},
149
+ use_cdn_fallback=True # Default - automatically falls back to local if CDN fails
150
+ )
151
+ ```
152
+
153
+ ### Prefer Local Files
154
+
155
+ ```python
156
+ from fastapi import FastAPI
157
+ from fastapi_docshield import DocShield
158
+
159
+ app = FastAPI()
160
+
161
+ # Always use local files instead of CDN
162
+ DocShield(
163
+ app=app,
164
+ credentials={"admin": "password123"},
165
+ prefer_local=True # Serve documentation from bundled static files
166
+ )
167
+ ```
168
+
169
+ ### CDN Only (No Fallback)
170
+
171
+ ```python
172
+ from fastapi import FastAPI
173
+ from fastapi_docshield import DocShield
174
+
175
+ app = FastAPI()
176
+
177
+ # Use CDN without fallback (original behavior)
178
+ DocShield(
179
+ app=app,
180
+ credentials={"admin": "password123"},
181
+ use_cdn_fallback=False # Disable fallback, CDN only
182
+ )
183
+ ```
184
+
185
+ ### Custom CSS and JavaScript
186
+
187
+ ```python
188
+ from fastapi import FastAPI
189
+ from fastapi_docshield import DocShield
190
+ import requests
191
+
192
+ app = FastAPI()
193
+
194
+ # Load dark theme CSS from external source
195
+ # You can use https://github.com/georgekhananaev/fastapi-swagger-dark
196
+ dark_theme_url = "https://raw.githubusercontent.com/georgekhananaev/fastapi-swagger-dark/main/src/fastapi_swagger_dark/swagger_ui_dark.min.css"
197
+ custom_css = requests.get(dark_theme_url).text
198
+
199
+ # Custom JavaScript for analytics
200
+ custom_js = """
201
+ console.log('📊 Documentation accessed at:', new Date().toISOString());
202
+ document.addEventListener('DOMContentLoaded', function() {
203
+ console.log('Dark theme loaded!');
204
+ });
205
+ """
206
+
207
+ # Apply with custom styling
208
+ DocShield(
209
+ app=app,
210
+ credentials={"admin": "password123"},
211
+ custom_css=custom_css,
212
+ custom_js=custom_js
213
+ )
214
+ ```
215
+
216
+ #### Using with fastapi-swagger-dark
217
+
218
+ For a complete dark theme solution, you can use the [fastapi-swagger-dark](https://github.com/georgekhananaev/fastapi-swagger-dark) package:
219
+
220
+ ```python
221
+ from fastapi import FastAPI
222
+ from fastapi_docshield import DocShield
223
+ import requests
224
+
225
+ app = FastAPI()
226
+
227
+ # Fetch dark theme CSS
228
+ response = requests.get(
229
+ "https://raw.githubusercontent.com/georgekhananaev/fastapi-swagger-dark/main/src/fastapi_swagger_dark/swagger_ui_dark.min.css"
230
+ )
231
+ dark_css = response.text
232
+
233
+ DocShield(
234
+ app=app,
235
+ credentials={"admin": "password123"},
236
+ custom_css=dark_css # Apply dark theme
237
+ )
238
+ ```
239
+
240
+ See [examples/custom_styling.py](examples/custom_styling.py) for more customization examples including:
241
+ - ✨ Minimal clean theme
242
+ - 🏢 Corporate theme with analytics
243
+ - 📖 ReDoc customization
244
+ - 🎨 Custom branding
245
+
112
246
  ## Running Demo
113
247
 
114
248
  ```bash
@@ -138,9 +272,36 @@ pytest --cov=fastapi_docshield
138
272
  - Protect Swagger UI, ReDoc, and OpenAPI JSON endpoints
139
273
  - Customizable endpoint URLs
140
274
  - Multiple username/password combinations
275
+ - **Automatic CDN fallback** - Falls back to local files if CDN is unavailable
276
+ - **Local file preference option** - Serve documentation from local files for better reliability
277
+ - **Custom CSS and JavaScript injection** - Fully customize the look and behavior of documentation
278
+ - **Resilient documentation** - Works even when CDN is down or blocked
141
279
  - Tested on Python 3.7-3.13
142
280
  - Compatible with uv package manager
143
281
 
282
+ ## Changelog
283
+
284
+ ### Version 0.2.0 (2025-08-17)
285
+ - **Added**: Custom CSS and JavaScript injection support
286
+ - New `custom_css` parameter to inject custom styles into documentation pages
287
+ - New `custom_js` parameter to inject custom JavaScript for enhanced functionality
288
+ - Complete customization examples for dark theme, minimal theme, corporate branding, and analytics
289
+ - Support for both Swagger UI and ReDoc customization
290
+ - **Added**: Automatic CDN fallback to local files for better reliability
291
+ - Documentation now automatically falls back to bundled static files if CDN is unavailable
292
+ - New `prefer_local` option to always serve from local files
293
+ - New `use_cdn_fallback` option to control fallback behavior
294
+ - Bundled Swagger UI and ReDoc static files for offline capability
295
+ - **Fixed**: Static file URL bug that caused blank documentation pages
296
+ - Previously, when no custom CDN URLs were provided, the package would pass `None` values to FastAPI's documentation functions
297
+ - This resulted in HTML with `href="None"` and `src="None"`, causing white/blank pages
298
+ - Now properly handles default CDN URLs when custom URLs are not specified
299
+
300
+ ### Version 0.1.0 (2025-01-15)
301
+ - Initial release
302
+ - Basic HTTP authentication for FastAPI documentation endpoints
303
+ - Support for multiple users
304
+
144
305
  ## License
145
306
 
146
307
  MIT License - Copyright (c) 2025 George Khananaev
@@ -0,0 +1,249 @@
1
+ # FastAPI DocShield
2
+
3
+ A simple FastAPI integration to protect documentation endpoints with HTTP Basic Authentication.
4
+
5
+ [![PyPI version](https://badge.fury.io/py/fastapi-docshield.svg)](https://badge.fury.io/py/fastapi-docshield)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+ [![Python Versions](https://img.shields.io/badge/python-3.7%20%7C%203.8%20%7C%203.9%20%7C%203.10%20%7C%203.11%20%7C%203.12%20%7C%203.13-blue)](https://github.com/georgekhananaev/fastapi-docshield)
8
+ [![Tests Status](https://img.shields.io/badge/tests-passing-brightgreen)](https://github.com/georgekhananaev/fastapi-docshield)
9
+ [![UV Compatible](https://img.shields.io/badge/uv-compatible-blueviolet)](https://github.com/astral-sh/uv)
10
+
11
+ ## About
12
+
13
+ Protect FastAPI's `/docs`, `/redoc`, and `/openapi.json` endpoints with HTTP Basic Authentication.
14
+
15
+ ## Installation
16
+
17
+ ### From PyPI
18
+
19
+ ```bash
20
+ # Install with pip
21
+ pip install fastapi-docshield
22
+
23
+ # Or with uv
24
+ uv pip install fastapi-docshield
25
+ ```
26
+
27
+ ### From Source
28
+
29
+ ```bash
30
+ git clone https://github.com/georgekhananaev/fastapi-docshield.git
31
+ cd fastapi-docshield
32
+ pip install -e .
33
+ ```
34
+
35
+ ## Quick Usage
36
+
37
+ ### Single User
38
+
39
+ ```python
40
+ from fastapi import FastAPI
41
+ from fastapi_docshield import DocShield
42
+
43
+ app = FastAPI()
44
+
45
+ @app.get("/")
46
+ def read_root():
47
+ return {"Hello": "World"}
48
+
49
+ # Add protection to docs with a single user
50
+ DocShield(
51
+ app=app,
52
+ credentials={"admin": "password123"}
53
+ )
54
+ ```
55
+
56
+ ### Multiple Users
57
+
58
+ ```python
59
+ from fastapi import FastAPI
60
+ from fastapi_docshield import DocShield
61
+
62
+ app = FastAPI()
63
+
64
+ @app.get("/")
65
+ def read_root():
66
+ return {"Hello": "World"}
67
+
68
+ # Add protection to docs with multiple users
69
+ DocShield(
70
+ app=app,
71
+ credentials={
72
+ "admin": "admin_password",
73
+ "developer": "dev_password",
74
+ "viewer": "viewer_password"
75
+ }
76
+ )
77
+ ```
78
+
79
+ ### CDN Fallback Mode (Default)
80
+
81
+ ```python
82
+ from fastapi import FastAPI
83
+ from fastapi_docshield import DocShield
84
+
85
+ app = FastAPI()
86
+
87
+ # Default mode: Use CDN with automatic fallback to local files
88
+ DocShield(
89
+ app=app,
90
+ credentials={"admin": "password123"},
91
+ use_cdn_fallback=True # Default - automatically falls back to local if CDN fails
92
+ )
93
+ ```
94
+
95
+ ### Prefer Local Files
96
+
97
+ ```python
98
+ from fastapi import FastAPI
99
+ from fastapi_docshield import DocShield
100
+
101
+ app = FastAPI()
102
+
103
+ # Always use local files instead of CDN
104
+ DocShield(
105
+ app=app,
106
+ credentials={"admin": "password123"},
107
+ prefer_local=True # Serve documentation from bundled static files
108
+ )
109
+ ```
110
+
111
+ ### CDN Only (No Fallback)
112
+
113
+ ```python
114
+ from fastapi import FastAPI
115
+ from fastapi_docshield import DocShield
116
+
117
+ app = FastAPI()
118
+
119
+ # Use CDN without fallback (original behavior)
120
+ DocShield(
121
+ app=app,
122
+ credentials={"admin": "password123"},
123
+ use_cdn_fallback=False # Disable fallback, CDN only
124
+ )
125
+ ```
126
+
127
+ ### Custom CSS and JavaScript
128
+
129
+ ```python
130
+ from fastapi import FastAPI
131
+ from fastapi_docshield import DocShield
132
+ import requests
133
+
134
+ app = FastAPI()
135
+
136
+ # Load dark theme CSS from external source
137
+ # You can use https://github.com/georgekhananaev/fastapi-swagger-dark
138
+ dark_theme_url = "https://raw.githubusercontent.com/georgekhananaev/fastapi-swagger-dark/main/src/fastapi_swagger_dark/swagger_ui_dark.min.css"
139
+ custom_css = requests.get(dark_theme_url).text
140
+
141
+ # Custom JavaScript for analytics
142
+ custom_js = """
143
+ console.log('📊 Documentation accessed at:', new Date().toISOString());
144
+ document.addEventListener('DOMContentLoaded', function() {
145
+ console.log('Dark theme loaded!');
146
+ });
147
+ """
148
+
149
+ # Apply with custom styling
150
+ DocShield(
151
+ app=app,
152
+ credentials={"admin": "password123"},
153
+ custom_css=custom_css,
154
+ custom_js=custom_js
155
+ )
156
+ ```
157
+
158
+ #### Using with fastapi-swagger-dark
159
+
160
+ For a complete dark theme solution, you can use the [fastapi-swagger-dark](https://github.com/georgekhananaev/fastapi-swagger-dark) package:
161
+
162
+ ```python
163
+ from fastapi import FastAPI
164
+ from fastapi_docshield import DocShield
165
+ import requests
166
+
167
+ app = FastAPI()
168
+
169
+ # Fetch dark theme CSS
170
+ response = requests.get(
171
+ "https://raw.githubusercontent.com/georgekhananaev/fastapi-swagger-dark/main/src/fastapi_swagger_dark/swagger_ui_dark.min.css"
172
+ )
173
+ dark_css = response.text
174
+
175
+ DocShield(
176
+ app=app,
177
+ credentials={"admin": "password123"},
178
+ custom_css=dark_css # Apply dark theme
179
+ )
180
+ ```
181
+
182
+ See [examples/custom_styling.py](examples/custom_styling.py) for more customization examples including:
183
+ - ✨ Minimal clean theme
184
+ - 🏢 Corporate theme with analytics
185
+ - 📖 ReDoc customization
186
+ - 🎨 Custom branding
187
+
188
+ ## Running Demo
189
+
190
+ ```bash
191
+ # Run the demo app
192
+ python demo.py
193
+
194
+ # Visit http://localhost:8000/docs
195
+ # Username: admin
196
+ # Password: password123
197
+ ```
198
+
199
+ ## Running Tests
200
+
201
+ ```bash
202
+ # Install test dependencies
203
+ pip install pytest httpx
204
+
205
+ # Run all tests
206
+ pytest
207
+
208
+ # Run with coverage
209
+ pytest --cov=fastapi_docshield
210
+ ```
211
+
212
+ ## Features
213
+
214
+ - Protect Swagger UI, ReDoc, and OpenAPI JSON endpoints
215
+ - Customizable endpoint URLs
216
+ - Multiple username/password combinations
217
+ - **Automatic CDN fallback** - Falls back to local files if CDN is unavailable
218
+ - **Local file preference option** - Serve documentation from local files for better reliability
219
+ - **Custom CSS and JavaScript injection** - Fully customize the look and behavior of documentation
220
+ - **Resilient documentation** - Works even when CDN is down or blocked
221
+ - Tested on Python 3.7-3.13
222
+ - Compatible with uv package manager
223
+
224
+ ## Changelog
225
+
226
+ ### Version 0.2.0 (2025-08-17)
227
+ - **Added**: Custom CSS and JavaScript injection support
228
+ - New `custom_css` parameter to inject custom styles into documentation pages
229
+ - New `custom_js` parameter to inject custom JavaScript for enhanced functionality
230
+ - Complete customization examples for dark theme, minimal theme, corporate branding, and analytics
231
+ - Support for both Swagger UI and ReDoc customization
232
+ - **Added**: Automatic CDN fallback to local files for better reliability
233
+ - Documentation now automatically falls back to bundled static files if CDN is unavailable
234
+ - New `prefer_local` option to always serve from local files
235
+ - New `use_cdn_fallback` option to control fallback behavior
236
+ - Bundled Swagger UI and ReDoc static files for offline capability
237
+ - **Fixed**: Static file URL bug that caused blank documentation pages
238
+ - Previously, when no custom CDN URLs were provided, the package would pass `None` values to FastAPI's documentation functions
239
+ - This resulted in HTML with `href="None"` and `src="None"`, causing white/blank pages
240
+ - Now properly handles default CDN URLs when custom URLs are not specified
241
+
242
+ ### Version 0.1.0 (2025-01-15)
243
+ - Initial release
244
+ - Basic HTTP authentication for FastAPI documentation endpoints
245
+ - Support for multiple users
246
+
247
+ ## License
248
+
249
+ MIT License - Copyright (c) 2025 George Khananaev
@@ -11,7 +11,7 @@ Copyright (c) 2025 George Khananaev
11
11
 
12
12
  from .docshield import DocShield
13
13
 
14
- __version__ = "0.1.0"
14
+ __version__ = "0.2.0"
15
15
  __author__ = "George Khananaev"
16
16
  __license__ = "MIT"
17
17
  __copyright__ = "Copyright (c) 2025 George Khananaev"