This repository was archived by the owner on May 3, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
51 lines (35 loc) · 1.31 KB
/
example.py
File metadata and controls
51 lines (35 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
from esmerald import Esmerald, EsmeraldAPISettings, Include
from esmerald.config.jwt import JWTConfig
from esmerald.contrib.auth.saffier.base_user import AbstractUser
from saffier import Database, Registry
from esmerald_admin import Admin
from esmerald_admin.backends.saffier.email import EmailAdminAuth
database = Database("sqlite:///db.sqlite")
registry = Registry(database=database)
class AppSettings(EsmeraldAPISettings):
@property
def jwt_config(self) -> JWTConfig:
return JWTConfig(signing_key=self.secret_key)
class User(AbstractUser):
"""Inherits from the user base"""
class Meta:
registry = registry
# You can use the `settings_module` directly or ESMERALD_SETTINGS_MODULE
settings = AppSettings()
def get_application():
"""
This is optional. The function is only used for organisation purposes.
"""
app = Esmerald(
routes=[Include(namespace="linezap.urls")],
on_startup=[database.connect],
on_shutdown=[database.disconnect],
settings_module=settings,
)
# EmailAdminAuth or UsernameAdminAuth
auth_backend = EmailAdminAuth(
secret_key=settings.secret_key, auth_model=User, config=settings.jwt_config
)
Admin(app, registry.engine, authentication_backend=auth_backend)
return app
app = get_application()