Core¶
tangram_core
¶
InjectBackendState
module-attribute
¶
InjectBackendState: TypeAlias = Annotated[
BackendState, Depends(get_state)
]
BackendState
dataclass
¶
Source code in packages/tangram_core/src/tangram_core/backend.py
51 52 53 54 55 | |
Config
dataclass
¶
Source code in packages/tangram_core/src/tangram_core/config.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
server
class-attribute
instance-attribute
¶
server: ServerConfig = field(default_factory=ServerConfig)
channel
class-attribute
instance-attribute
¶
channel: ChannelConfig = field(
default_factory=ChannelConfig
)
from_file
classmethod
¶
Source code in packages/tangram_core/src/tangram_core/config.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
Plugin
dataclass
¶
Stores the metadata and registered API routes, background services and frontend assets for a tangram plugin.
Packages should declare an entry point in the tangram_core.plugins group
in their pyproject.toml pointing to an instance of this class.
Source code in packages/tangram_core/src/tangram_core/plugin.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
frontend_path
class-attribute
instance-attribute
¶
frontend_path: str | None = None
Path to the compiled frontend assets, relative to the distribution root (editable) or package root (wheel).
into_frontend_config_function
class-attribute
instance-attribute
¶
into_frontend_config_function: (
IntoFrontendConfigFunction | None
) = None
Function to parse plugin-scoped backend configuration (within the
tangram.toml) into a frontend-safe configuration object.
If not specified, the backend configuration dict is passed as-is.
lifespan
class-attribute
instance-attribute
¶
lifespan: Lifespan | None = None
Async context manager for plugin initialization and teardown.
services
class-attribute
instance-attribute
¶
dist_name
class-attribute
instance-attribute
¶
Name of the distribution (package) that provided this plugin, populated automatically during loading.
register_service
¶
register_service(
priority: Priority = 0,
) -> Callable[[ServiceFunc], ServiceFunc]
Decorator to register a background service function.
Services are long-running async functions that receive the BackendState and are started when the application launches.
Source code in packages/tangram_core/src/tangram_core/plugin.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
backend
¶
InjectBackendState
module-attribute
¶
InjectBackendState: TypeAlias = Annotated[
BackendState, Depends(get_state)
]
BackendState
dataclass
¶
Source code in packages/tangram_core/src/tangram_core/backend.py
51 52 53 54 55 | |
get_state
async
¶
get_state(request: Request) -> BackendState
Source code in packages/tangram_core/src/tangram_core/backend.py
58 59 | |
get_distribution_path
¶
Get the local path of a distribution, handling both editable installs
(direct_url.json) and standard wheel installs.
See: https://packaging.python.org/en/latest/specifications/direct-url-data-structure/
Source code in packages/tangram_core/src/tangram_core/backend.py
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 | |
resolve_frontend
¶
Source code in packages/tangram_core/src/tangram_core/backend.py
96 97 98 99 | |
load_enabled_plugins
¶
Source code in packages/tangram_core/src/tangram_core/backend.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
lifespan
async
¶
lifespan(
app: FastAPI,
backend_state: BackendState,
loaded_plugins: Iterable[Plugin],
) -> AsyncGenerator[None, None]
Source code in packages/tangram_core/src/tangram_core/backend.py
118 119 120 121 122 123 124 125 126 127 128 129 | |
default_cache_dir
¶
default_cache_dir() -> Path
Source code in packages/tangram_core/src/tangram_core/backend.py
132 133 134 135 136 137 138 139 140 | |
make_cache_route_handler
¶
make_cache_route_handler(
entry: CacheEntry, state: BackendState
) -> Callable[..., Awaitable[FileResponse]]
Factory function that creates a route handler for caching and serving files. Dynamically handles URL parameters found in both serve_route and origin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entry
|
CacheEntry
|
Cache entry configuration |
required |
state
|
BackendState
|
Backend state with http_client for fetching remote resources |
required |
Returns:
| Type | Description |
|---|---|
Callable[..., Awaitable[FileResponse]]
|
Async function that handles the route with dynamic parameters |
Source code in packages/tangram_core/src/tangram_core/backend.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | |
create_app
¶
create_app(
backend_state: BackendState,
loaded_plugins: Iterable[Plugin],
) -> FastAPI
Source code in packages/tangram_core/src/tangram_core/backend.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | |
run_channel_service
async
¶
run_channel_service(config: Config) -> None
Source code in packages/tangram_core/src/tangram_core/backend.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 | |
run_services
async
¶
run_services(
backend_state: BackendState,
loaded_plugins: Iterable[Plugin],
) -> AsyncGenerator[Task[None], None]
Source code in packages/tangram_core/src/tangram_core/backend.py
321 322 323 324 325 326 327 328 329 330 331 332 | |
run_server
async
¶
run_server(
backend_state: BackendState,
loaded_plugins: list[Plugin],
) -> None
Source code in packages/tangram_core/src/tangram_core/backend.py
335 336 337 338 339 340 341 342 343 344 | |
start_tasks
async
¶
start_tasks(config: Config) -> None
Source code in packages/tangram_core/src/tangram_core/backend.py
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | |
get_log_config_dict
¶
Source code in packages/tangram_core/src/tangram_core/backend.py
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 | |
config
¶
HasTopbarUiConfig
¶
HasSidebarUiConfig
¶
ServerConfig
dataclass
¶
ChannelConfig
dataclass
¶
Source code in packages/tangram_core/src/tangram_core/config.py
25 26 27 28 29 30 31 32 33 34 | |
UrlConfig
dataclass
¶
SourceSpecification
dataclass
¶
Source code in packages/tangram_core/src/tangram_core/config.py
43 44 45 46 | |
StyleSpecification
dataclass
¶
Source code in packages/tangram_core/src/tangram_core/config.py
49 50 51 52 53 54 | |
MapConfig
dataclass
¶
Source code in packages/tangram_core/src/tangram_core/config.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
style
class-attribute
instance-attribute
¶
style: str | StyleSpecification = (
"https://basemaps.cartocdn.com/gl/voyager-gl-style/style.json"
)
CoreConfig
dataclass
¶
Source code in packages/tangram_core/src/tangram_core/config.py
80 81 82 83 84 | |
CacheEntry
dataclass
¶
Source code in packages/tangram_core/src/tangram_core/config.py
87 88 89 90 91 92 93 94 95 96 | |
origin
class-attribute
instance-attribute
¶
origin: str | None = None
Origin URL. If None, the local file is served directly.
local_path
class-attribute
instance-attribute
¶
local_path: Path | None = None
Local path to cache the file.
CacheConfig
dataclass
¶
Source code in packages/tangram_core/src/tangram_core/config.py
99 100 101 | |
entries
class-attribute
instance-attribute
¶
entries: list[CacheEntry] = field(default_factory=list)
Config
dataclass
¶
Source code in packages/tangram_core/src/tangram_core/config.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
server
class-attribute
instance-attribute
¶
server: ServerConfig = field(default_factory=ServerConfig)
channel
class-attribute
instance-attribute
¶
channel: ChannelConfig = field(
default_factory=ChannelConfig
)
from_file
classmethod
¶
Source code in packages/tangram_core/src/tangram_core/config.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
FrontendChannelConfig
dataclass
¶
FrontendConfig
dataclass
¶
Source code in packages/tangram_core/src/tangram_core/config.py
141 142 143 144 | |
plugin
¶
ServiceAsyncFunc
module-attribute
¶
ServiceAsyncFunc: TypeAlias = Callable[
[BackendState], Awaitable[None]
]
ServiceFunc
module-attribute
¶
ServiceFunc: TypeAlias = (
ServiceAsyncFunc | Callable[[BackendState], None]
)
IntoFrontendConfigFunction
module-attribute
¶
Lifespan
module-attribute
¶
Lifespan: TypeAlias = Callable[
[BackendState], AsyncGenerator[None, None]
]
Plugin
dataclass
¶
Stores the metadata and registered API routes, background services and frontend assets for a tangram plugin.
Packages should declare an entry point in the tangram_core.plugins group
in their pyproject.toml pointing to an instance of this class.
Source code in packages/tangram_core/src/tangram_core/plugin.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
frontend_path
class-attribute
instance-attribute
¶
frontend_path: str | None = None
Path to the compiled frontend assets, relative to the distribution root (editable) or package root (wheel).
into_frontend_config_function
class-attribute
instance-attribute
¶
into_frontend_config_function: (
IntoFrontendConfigFunction | None
) = None
Function to parse plugin-scoped backend configuration (within the
tangram.toml) into a frontend-safe configuration object.
If not specified, the backend configuration dict is passed as-is.
lifespan
class-attribute
instance-attribute
¶
lifespan: Lifespan | None = None
Async context manager for plugin initialization and teardown.
services
class-attribute
instance-attribute
¶
dist_name
class-attribute
instance-attribute
¶
Name of the distribution (package) that provided this plugin, populated automatically during loading.
register_service
¶
register_service(
priority: Priority = 0,
) -> Callable[[ServiceFunc], ServiceFunc]
Decorator to register a background service function.
Services are long-running async functions that receive the BackendState and are started when the application launches.
Source code in packages/tangram_core/src/tangram_core/plugin.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
scan_plugins
¶
scan_plugins() -> EntryPoints
Source code in packages/tangram_core/src/tangram_core/plugin.py
78 79 | |
load_plugin
¶
load_plugin(entry_point: EntryPoint) -> Plugin | None
Instantiates the plugin object defined in the entry point and injects the name of the distribution into it.
Source code in packages/tangram_core/src/tangram_core/plugin.py
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 | |
redis
¶
Subscriber
¶
Source code in packages/tangram_core/src/tangram_core/redis.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 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 | |
subscribe
async
¶
subscribe() -> None
Source code in packages/tangram_core/src/tangram_core/redis.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
cleanup
async
¶
cleanup() -> None
Source code in packages/tangram_core/src/tangram_core/redis.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
is_active
¶
is_active() -> bool
Return True if the subscriber is actively listening.
Source code in packages/tangram_core/src/tangram_core/redis.py
81 82 83 | |
message_handler
abstractmethod
async
¶
Source code in packages/tangram_core/src/tangram_core/redis.py
85 86 87 88 89 | |
tangram_core._core
¶
ChannelConfig
¶
__new__
¶
__new__(
host: str,
port: int,
redis_url: str,
jwt_secret: str,
jwt_expiration_secs: int,
id_length: int,
) -> ChannelConfig