Skip to content

Python wrapper package for precompiled Bootstrap assets #41294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*.vi
*.zip
*~
*.pyc

# OS or Editor folders
._*
Expand All @@ -41,3 +42,5 @@ Thumbs.db
/dist-sass/
/js/coverage/
/node_modules/
build/lib/
*.egg-info/
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
recursive-include dist *
26 changes: 26 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[build-system]
requires = ["setuptools>=42", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "bootstrap"
dynamic = ["version"]
description = "A wrapper to distribute Bootstrap via a python package"
readme = "README.md"
requires-python = ">=3.7"
license = { text = "MIT" }
authors = [
{ name = "Mark Otto", email = "markdotto@gmail.com" },
{ name = "Jacob Thornton", email = "jacobthornton@gmail.com" }
]

[tool.setuptools.dynamic]
version = { attr = "bootstrap.__version__" }

[project.urls]
Homepage = "https://github.com/twbs/bootstrap"

[tool.setuptools]
packages = ["bootstrap", "bootstrap.dist"]
package-dir = { "bootstrap" = "python", "bootstrap.dist" = "dist" }
include-package-data = true
17 changes: 17 additions & 0 deletions python/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""
Load the package.json to get the current version of the package for the installer
"""

import json
from pathlib import Path

try:
# Loading package.json
package_json_path = Path(__file__).parent.parent / "package.json"
with package_json_path.open(encoding="utf-8") as f:
data = json.load(f)

# to get current version
__version__ = data["version"]
except Exception as e: # pylint: disable=broad-exception-caught
__version__ = "0.0.0"
29 changes: 29 additions & 0 deletions site/content/docs/5.3/getting-started/download.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,32 @@ Install-Package bootstrap
```powershell
Install-Package bootstrap.sass
```

### Python

Bootstrap is now installable as a Python package, allowing you to integrate the compiled Bootstrap assets directly into your Python projects. Installation via pip is now supported:

```sh
pip install git+https://github.com/twbs/bootstrap.git
```

After installation, the Bootstrap assets (CSS and JS files) are embedded as package data and can be served directly in your Python web application. For example, in a FastAPI app you can serve these static assets under the `/bootstrap` URL path:

```python
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from pathlib import Path
import importlib.metadata

app = FastAPI()

# Retrieve the distribution information for the 'bootstrap' package.
dist = importlib.metadata.distribution("bootstrap")

# Locate the static assets installed as package data.
static_path = Path(dist.locate_file("bootstrap/dist"))

app.mount("/bootstrap", StaticFiles(directory=str(static_path)), name="bootstrap")
```

In this configuration, you can access Bootstrap's CSS at `/bootstrap/css/bootstrap.min.css` and JavaScript at `/bootstrap/js/bootstrap.bundle.min.js` in your application.