API Reference
This section provides automatically generated documentation from the FastStrap source code. It is useful for looking up exact parameter names and types.
Core Utilities
faststrap.core.theme.resolve_defaults(component, **kwargs)
Resolve component attributes by merging defaults with user arguments.
Priority (highest to lowest): 1. Explicit user arguments (if not None) 2. Global component defaults (set via set_component_defaults)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
component
|
str
|
Component name (e.g., "Button") |
required |
**kwargs
|
Any
|
Arguments passed by the user |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict of resolved attributes |
Example
set_component_defaults("Button", variant="secondary") resolve_defaults("Button", variant=None, size="lg")
Source code in src/faststrap/core/theme.py
faststrap.core.base.merge_classes(*class_lists)
Merge multiple class strings or lists, removing duplicates.
Source code in src/faststrap/core/base.py
Attributes Helper
faststrap.utils.attrs.convert_attrs(kwargs)
Convert Python kwargs to HTML attributes (hx_get -> hx-get).
Rules:
- None values are dropped
- boolean False values are dropped (except aria_*, which are preserved)
- boolean True values are kept (FastHTML will serialize appropriately)
- style may be a str or a dict (dict is serialized)
- css_vars may be a dict and will be merged into style
- data={...} expands to data-*
- aria={...} expands to aria-*
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kwargs
|
dict[str, Any]
|
Python-style keyword arguments |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
HTML-style attributes with hyphens |
Source code in src/faststrap/utils/attrs.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
Application Setup
faststrap.core.assets.add_bootstrap(app, theme=None, mode='light', use_cdn=None, mount_static=True, static_url='/static', force_static_url=False, include_favicon=True, favicon_url=None, font_family=None, font_weights=None, components=None)
Enhance FastHTML app with Bootstrap and FastStrap assets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app
|
Any
|
FastHTML application instance |
required |
theme
|
str | Theme | None
|
Color theme - either a built-in name (e.g., "green-nature", "purple-magic"), a Theme instance created via create_theme(), or a community theme |
None
|
mode
|
ModeType
|
Color mode for light/dark backgrounds: - "light": Light background, dark text (default) - "dark": Dark background, light text - "auto": Follows user's system preference (prefers-color-scheme) |
'light'
|
use_cdn
|
bool | None
|
When True, ALL assets (Bootstrap CSS/JS, Bootstrap Icons, Faststrap CSS files, favicon) are served from CDN. No local StaticFiles are mounted. Required for serverless deployments (Vercel, AWS Lambda, Google Cloud Run). Default: False. |
None
|
mount_static
|
bool
|
Auto-mount static directory |
True
|
static_url
|
str
|
Preferred URL prefix for static files |
'/static'
|
force_static_url
|
bool
|
Force use of this URL even if already mounted |
False
|
include_favicon
|
bool
|
Include default FastStrap favicon |
True
|
favicon_url
|
str | None
|
Custom favicon URL (overrides default) |
None
|
font_family
|
str | None
|
Google Font name (e.g., "Inter", "Roboto", "Poppins") |
None
|
font_weights
|
list[int] | None
|
Font weights to load (default: [400, 500, 700]) |
None
|
components
|
list[Any] | None
|
Optional list of Faststrap component functions used in the app. When provided, Bootstrap JS is only injected if at least one component has requires_js=True in its registry metadata. Components without @register() metadata are treated as requires_js=False. When None (default), JS is always injected. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
Modified app instance |
Example
Basic setup with light mode
add_bootstrap(app)
Dark mode with a color theme
add_bootstrap(app, theme="purple-magic", mode="dark")
Auto mode (follows system preference)
add_bootstrap(app, theme="green-nature", mode="auto")
Custom theme with dark mode
from faststrap import create_theme my_theme = create_theme(primary="#7BA05B", secondary="#48C774") add_bootstrap(app, theme=my_theme, mode="dark")
Built-in theme with custom font
add_bootstrap(app, theme="green-nature", font_family="Inter")
Custom theme with custom font
my_theme = create_theme(primary="#7BA05B") add_bootstrap(app, theme=my_theme, font_family="Roboto", font_weights=[400, 600, 700])
Font only, no theme
add_bootstrap(app, font_family="Poppins")
CDN mode for production
add_bootstrap(app, theme="blue-ocean", mode="auto", use_cdn=True)
Source code in src/faststrap/core/assets.py
754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 | |
faststrap.utils.static_management.get_faststrap_static_url(app)
Get the URL where FastStrap static files are mounted for this specific app.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app
|
Any
|
The FastHTML app instance |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The static URL if mounted, None otherwise |
Source code in src/faststrap/utils/static_management.py
Theme System
Notes:
- add_bootstrap() supports font_family and font_weights for Google Fonts injection.
- set_component_defaults() modifies process-global defaults. Configure it at application startup.
- BaseComponent / Component are extension points for third-party class-based components; built-ins remain function-based.
faststrap.core.theme.create_theme(primary=None, secondary=None, success=None, danger=None, warning=None, info=None, **extra_vars)
Create a custom theme from color values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
primary
|
str | None
|
Primary color (e.g., "#7BA05B") |
None
|
secondary
|
str | None
|
Secondary color |
None
|
success
|
str | None
|
Success color (defaults to Bootstrap green) |
None
|
danger
|
str | None
|
Danger color (defaults to Bootstrap red) |
None
|
warning
|
str | None
|
Warning color (defaults to Bootstrap yellow) |
None
|
info
|
str | None
|
Info color (defaults to Bootstrap cyan) |
None
|
**extra_vars
|
str
|
Additional CSS variables |
{}
|
Returns:
| Type | Description |
|---|---|
Theme
|
Theme instance |
Example
theme = create_theme( ... primary="#7BA05B", ... secondary="#48C774", ... ) add_bootstrap(app, theme=theme, mode="dark")
Source code in src/faststrap/core/theme.py
faststrap.core.theme.set_component_defaults(component, **defaults)
Set default values for a component globally.
This updates process-global state shared by all requests. Configure defaults during application startup.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
component
|
str
|
Component name (e.g., "Button") |
required |
**defaults
|
Any
|
Default values to set |
{}
|
Example
set_component_defaults("Button", variant="outline-primary", size="sm")
Now all Button() calls use these defaults unless overridden
Source code in src/faststrap/core/theme.py
faststrap.core.theme.reset_component_defaults(component=None)
Reset component defaults to original values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
component
|
str | None
|
Component name to reset, or None to reset all |
None
|