Skip to content

Base Repositories

fastauth.repositories.AbstractUserRepository

Bases: Generic[UP, ID], ABC

user_model instance-attribute

user_model

get_by_id abstractmethod async

get_by_id(pk)

Get user by id

PARAMETER DESCRIPTION
pk

User id

TYPE: ID

RETURNS DESCRIPTION
UP | None

User model or None

Source code in fastauth/repositories.py
12
13
14
15
16
17
18
19
@abstractmethod
async def get_by_id(self, pk: ID) -> UP | None:
    """
    Get user by id
    :param pk: User id
    :return: User model or None
    """
    raise NotImplementedError

get_by_email abstractmethod async

get_by_email(email)

Get user by email

PARAMETER DESCRIPTION
email

User email

TYPE: str

Source code in fastauth/repositories.py
21
22
23
24
25
26
27
28
29
@abstractmethod
async def get_by_email(self, email: str) -> UP | None:
    """
    Get user by email
    :param email: User email
    :return User model or None
    """

    raise NotImplementedError

get_by_username abstractmethod async

get_by_username(username)

Get user by email

PARAMETER DESCRIPTION
username

User username

TYPE: str

Source code in fastauth/repositories.py
31
32
33
34
35
36
37
38
@abstractmethod
async def get_by_username(self, username: str) -> UP | None:
    """
    Get user by email
    :param username: User username
    :return User model or None
    """
    raise NotImplementedError

get_by_fields abstractmethod async

get_by_fields(value, fields)

Get user by multiple fields and username. Just check in cycle if user. == username

PARAMETER DESCRIPTION
value

User field value

TYPE: str

fields

list of fields on user model

TYPE: list[str]

Source code in fastauth/repositories.py
40
41
42
43
44
45
46
47
48
@abstractmethod
async def get_by_fields(self, value: str, fields: list[str]) -> UP | None:
    """
    Get user by multiple fields and username. Just check in cycle if user.<field> == username
    :param value: User field value
    :param fields: list of fields on user model
    :return User model or None
    """
    raise NotImplementedError

get_by_field abstractmethod async

get_by_field(value, field)

Get user by his value in field

PARAMETER DESCRIPTION
value

User model field value

TYPE: Any

field

User model field name

TYPE: str

RETURNS DESCRIPTION
UP | None

User model or None

Source code in fastauth/repositories.py
50
51
52
53
54
55
56
57
58
@abstractmethod
async def get_by_field(self, value: Any, field: str) -> UP | None:
    """
    Get user by his value in field
    :param value: User model field value
    :param field: User model field name
    :return: User model or None
    """
    raise NotImplementedError

create abstractmethod async

create(data)

Create User in DB from data dict

PARAMETER DESCRIPTION
data

User model payload

TYPE: dict[str, Any]

Source code in fastauth/repositories.py
60
61
62
63
64
65
66
67
@abstractmethod
async def create(self, data: dict[str, Any]) -> UP:
    """
    Create User in DB from data dict
    :param data: User model payload
    :return New User model
    """
    raise NotImplementedError

update abstractmethod async

update(user, data)

Update provided user model with provided data

PARAMETER DESCRIPTION
user

User model

TYPE: UP

data

Data with which updates user

TYPE: dict[str, Any]

Source code in fastauth/repositories.py
69
70
71
72
73
74
75
76
77
@abstractmethod
async def update(self, user: UP, data: dict[str, Any]) -> UP:
    """
    Update provided user model with provided data
    :param user: User model
    :param data: Data with which updates user
    :return Updated user model"""

    raise NotImplementedError

delete abstractmethod async

delete(user)

Delete provided user model from db

PARAMETER DESCRIPTION
user

User model

TYPE: UP

Source code in fastauth/repositories.py
79
80
81
82
83
84
85
86
@abstractmethod
async def delete(self, user: UP) -> None:
    """
    Delete provided user model from db
    :param user: User model
    :return None
    """
    raise NotImplementedError

fastauth.repositories.AbstractRolePermissionRepository

Bases: Generic[RP, PP], ABC

role_model instance-attribute

role_model

permission_model instance-attribute

permission_model

get_role abstractmethod async

get_role(role_id)

Ger role by id

PARAMETER DESCRIPTION
role_id

INTEGER Primary key

TYPE: int

RETURNS DESCRIPTION
RP | None

Role model

Source code in fastauth/repositories.py
 93
 94
 95
 96
 97
 98
 99
100
101
@abstractmethod
async def get_role(self, role_id: int) -> RP | None:
    """
    Ger role by id
    :param role_id: INTEGER Primary key
    :return: Role model
    """

    raise NotImplementedError

get_role_by_codename abstractmethod async

get_role_by_codename(codename)

Ger role by codename

PARAMETER DESCRIPTION
codename

Role codename

TYPE: str

RETURNS DESCRIPTION
RP | None

Role model

Source code in fastauth/repositories.py
103
104
105
106
107
108
109
110
@abstractmethod
async def get_role_by_codename(self, codename: str) -> RP | None:
    """
    Ger role by codename
    :param codename: Role codename
    :return: Role model
    """
    raise NotImplementedError

create_role abstractmethod async

create_role(data)

Create new role in db from data dict

PARAMETER DESCRIPTION
data

Role model payload

TYPE: dict[str, Any]

RETURNS DESCRIPTION
RP

New Role model

Source code in fastauth/repositories.py
112
113
114
115
116
117
118
119
@abstractmethod
async def create_role(self, data: dict[str, Any]) -> RP:
    """
    Create new role in db from data dict
    :param data: Role model payload
    :return: New Role model
    """
    raise NotImplementedError

update_role abstractmethod async

update_role(role, data)

Update provided role model with provided data

PARAMETER DESCRIPTION
role

Role model

TYPE: RP

data

Data with which updates role

TYPE: dict[str, Any]

RETURNS DESCRIPTION
RP

Updated role model

Source code in fastauth/repositories.py
121
122
123
124
125
126
127
128
129
@abstractmethod
async def update_role(self, role: RP, data: dict[str, Any]) -> RP:
    """
    Update provided role model with provided data
    :param role: Role model
    :param data: Data with which updates role
    :return: Updated role model
    """
    raise NotImplementedError

delete_role abstractmethod async

delete_role(role)

Delete provided role model from db

PARAMETER DESCRIPTION
role

Role model

TYPE: RP

RETURNS DESCRIPTION
None

None

Source code in fastauth/repositories.py
131
132
133
134
135
136
137
138
@abstractmethod
async def delete_role(self, role: RP) -> None:
    """
    Delete provided role model from db
    :param role: Role model
    :return: None
    """
    raise NotImplementedError

list_roles abstractmethod async

list_roles()

List all roles

RETURNS DESCRIPTION
list[RP]

List of Role models

Source code in fastauth/repositories.py
140
141
142
143
144
145
146
@abstractmethod
async def list_roles(self) -> list[RP]:
    """
    List all roles
    :return: List of Role models
    """
    raise NotImplementedError

get_permission abstractmethod async

get_permission(permission_id)

Get permission by id

PARAMETER DESCRIPTION
permission_id

INTEGER Primary key

TYPE: int

RETURNS DESCRIPTION
PP | None

Permission model

Source code in fastauth/repositories.py
148
149
150
151
152
153
154
155
@abstractmethod
async def get_permission(self, permission_id: int) -> PP | None:
    """
    Get permission by id
    :param permission_id: INTEGER Primary key
    :return: Permission model
    """
    raise NotImplementedError

get_permission_by_codename abstractmethod async

get_permission_by_codename(codename)

Get permission by codename

PARAMETER DESCRIPTION
codename

Permission codename

TYPE: str

RETURNS DESCRIPTION
PP | None

Permission model

Source code in fastauth/repositories.py
157
158
159
160
161
162
163
164
@abstractmethod
async def get_permission_by_codename(self, codename: str) -> PP | None:
    """
    Get permission by codename
    :param codename: Permission codename
    :return: Permission model
    """
    raise NotImplementedError

create_permission abstractmethod async

create_permission(data)

Create new permission in db from data dict

PARAMETER DESCRIPTION
data

Permission model payload

TYPE: dict[str, Any]

RETURNS DESCRIPTION
PP

New Permission model

Source code in fastauth/repositories.py
166
167
168
169
170
171
172
173
@abstractmethod
async def create_permission(self, data: dict[str, Any]) -> PP:
    """
    Create new permission in db from data dict
    :param data: Permission model payload
    :return: New Permission model
    """
    raise NotImplementedError

update_permission abstractmethod async

update_permission(permission, data)

Update provided permission model with provided data

PARAMETER DESCRIPTION
permission

Permission model

TYPE: PP

data

Data with which updates permission

TYPE: dict[str, Any]

RETURNS DESCRIPTION
PP

Updated permission model

Source code in fastauth/repositories.py
175
176
177
178
179
180
181
182
183
@abstractmethod
async def update_permission(self, permission: PP, data: dict[str, Any]) -> PP:
    """
    Update provided permission model with provided data
    :param permission: Permission model
    :param data: Data with which updates permission
    :return: Updated permission model
    """
    raise NotImplementedError

delete_permission abstractmethod async

delete_permission(permission)

Delete provided permission model from db

PARAMETER DESCRIPTION
permission

Permission model

TYPE: PP

RETURNS DESCRIPTION
None

None

Source code in fastauth/repositories.py
185
186
187
188
189
190
191
192
@abstractmethod
async def delete_permission(self, permission: PP) -> None:
    """
    Delete provided permission model from db
    :param permission: Permission model
    :return: None
    """
    raise NotImplementedError

list_permissions abstractmethod async

list_permissions()

List all permissions

RETURNS DESCRIPTION
list[PP]

List of Permission models

Source code in fastauth/repositories.py
194
195
196
197
198
199
200
@abstractmethod
async def list_permissions(self) -> list[PP]:
    """
    List all permissions
    :return: List of Permission models
    """
    raise NotImplementedError

fastauth.repositories.AbstractOAuthRepository

Bases: Generic[UOAP, OAP], ABC

user_model instance-attribute

user_model

oauth_model instance-attribute

oauth_model

get_user abstractmethod async

get_user(oauth_name, account_id)

Get user by oauth account name and id

PARAMETER DESCRIPTION
oauth_name

OAuth client name

TYPE: str

account_id

OAuthAccount model PK

TYPE: str

RETURNS DESCRIPTION
UOAP | None

User model

Source code in fastauth/repositories.py
207
208
209
210
211
212
213
214
215
@abstractmethod
async def get_user(self, oauth_name: str, account_id: str) -> UOAP | None:
    """
    Get user by oauth account name and id
    :param oauth_name: OAuth client name
    :param account_id: OAuthAccount model PK
    :return: User model
    """
    raise NotImplementedError

add_oauth_account abstractmethod async

add_oauth_account(user, data)

Create a new OAuth account and add it to User model

PARAMETER DESCRIPTION
user

User model

TYPE: UOAP

data

OAuth Account data

TYPE: dict[str, Any]

RETURNS DESCRIPTION
UOAP

User model

Source code in fastauth/repositories.py
217
218
219
220
221
222
223
224
225
@abstractmethod
async def add_oauth_account(self, user: UOAP, data: dict[str, Any]) -> UOAP:
    """
    Create a new OAuth account and add it to User model
    :param user: User model
    :param data: OAuth Account data
    :return: User model
    """
    raise NotImplementedError

update_oauth_account abstractmethod async

update_oauth_account(user, oauth, data)

Update provided OAuth account with provided data, and refresh user in DB

PARAMETER DESCRIPTION
user

User model

TYPE: UOAP

oauth

OAuthAccount model

TYPE: OAP

data

Data with which updates OAuth account

TYPE: dict[str, Any]

RETURNS DESCRIPTION
UOAP

Updated User model

Source code in fastauth/repositories.py
227
228
229
230
231
232
233
234
235
236
237
238
@abstractmethod
async def update_oauth_account(
    self, user: UOAP, oauth: OAP, data: dict[str, Any]
) -> UOAP:
    """
    Update provided OAuth account with provided data, and refresh user in DB
    :param user: User model
    :param oauth: OAuthAccount model
    :param data: Data with which updates OAuth account
    :return: Updated User model
    """
    raise NotImplementedError