arbor_imago package

Subpackages

Submodules

arbor_imago.app module

async arbor_imago.app.custom_http_exception_handler(request: Request, exc: HTTPException)[source]
arbor_imago.app.lifespan(app: FastAPI)[source]

arbor_imago.cli module

arbor_imago.cli.create_tables()[source]

Create all database tables.

arbor_imago.cli.export_api_schema()[source]

Export OpenAPI schema to file.

arbor_imago.cli.runserver()[source]

arbor_imago.config module

class arbor_imago.config.AccessTokenCookie[source]

Bases: TypedDict

httponly: NotRequired[bool]
key: str
samesite: NotRequired[Literal['lax', 'strict', 'none']]
secure: NotRequired[bool]
class arbor_imago.config.AuthConfig[source]

Bases: TypedDict

credential_lifespans: dict[Literal['access_token', 'magic_link', 'request_sign_up', 'otp'], timedelta]
class arbor_imago.config.AuthEnv[source]

Bases: TypedDict

credential_lifespans: dict[Literal['access_token', 'magic_link', 'request_sign_up', 'otp'], Annotated[str, 'ISO 8601 duration string']]
class arbor_imago.config.BackendConfig[source]

Bases: TypedDict

AUTH: AuthEnv
DB: DbEnv
GOOGLE_CLIENT_PATH: str
MEDIA_DIR: str
OPENAPI_SCHEMA_PATHS: dict[Literal['gallery'], str | PathLike[str]]
UVICORN: dict
class arbor_imago.config.BackendSecrets[source]

Bases: TypedDict

JWT_ALGORITHM: str
JWT_SECRET_KEY: str
class arbor_imago.config.DbEnv[source]

Bases: TypedDict

URL: str
class arbor_imago.config.SharedConfig[source]

Bases: TypedDict

AUTH_KEY: str
BACKEND_URL: str
FRONTEND_ROUTES: dict[str, str]
FRONTEND_URL: str
GOOGLE_CLIENT_ID: str
HEADER_KEYS: dict[str, str]
OTP_LENGTH: int
PERMISSION_LEVEL_NAME_MAPPING: dict[Literal['editor', 'viewer'], int]
SCOPE_NAME_MAPPING: dict[Literal['admin', 'users.read', 'users.write'], int]
USER_ROLE_NAME_MAPPING: dict[Literal['admin', 'user'], int]
USER_ROLE_SCOPES: dict[Literal['admin', 'user'], list[Literal['admin', 'users.read', 'users.write']]]
VISIBILITY_LEVEL_NAME_MAPPING: dict[Literal['public', 'private'], int]
arbor_imago.config.convert_env_path_to_absolute(root_dir: Path, a: str | PathLike[str]) Path[source]

process a relative path sent to an environment variable

arbor_imago.config.process_explicit_config_path(config_path: str | None) Path | None[source]

process an explicit config path sent to an environment variable

arbor_imago.core_utils module

arbor_imago.core_utils.deep_merge_dicts(primary_dict: dict, secondary_dict: dict) dict[source]

Recursive dict merge. Inspired by :meth:dict.update(), instead of updating only top-level keys, dict_merge recurses down into dicts nested to an arbitrary depth, updating keys. The secondary_dict is merged into primary_dict. :param primary_dict: dict onto which the merge is executed :param secondary_dict: primary_dict merged into primary_dict :return: None

arbor_imago.core_utils.generate_jwt_secret_key() str[source]
arbor_imago.core_utils.generate_uuid() str[source]
arbor_imago.core_utils.hash_password(password: str) str[source]
arbor_imago.core_utils.verify_password(plain_password: str, hashed_password: str) bool[source]

arbor_imago.custom_types module

class arbor_imago.custom_types.ApiKey[source]

Bases: AuthCredential

id

alias of str

name

alias of Annotated[str, StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=256, pattern=None)]

order_by

alias of Literal[‘issued’, ‘expiry’, ‘name’]

class arbor_imago.custom_types.ApiKeyScope[source]

Bases: _ApiKeyScopeBase

id

alias of ApiKeyScopeId

class arbor_imago.custom_types.ApiKeyScopeId(api_key_id, scope_id)[source]

Bases: NamedTuple

api_key_id: str

Alias for field number 0

scope_id: int

Alias for field number 1

class arbor_imago.custom_types.AuthCredential[source]

Bases: object

expiry

alias of Annotated[datetime, ‘The datetime at which the auth credential will expire’]

expiry_timestamp

alias of Annotated[float, ‘The datetime at which the auth credential will expire’]

issued

alias of Annotated[datetime, ‘The datetime at which the auth credential was issued’]

issued_timestamp

alias of Annotated[float, ‘The datetime at which the auth credential was issued’]

type

alias of Literal[‘access_token’, ‘api_key’, ‘otp’, ‘sign_up’]

class arbor_imago.custom_types.File[source]

Bases: object

gallery_id

alias of str

id

alias of str

size

alias of int

stem

alias of str

suffix

alias of Annotated[str, StringConstraints(strip_whitespace=None, to_upper=None, to_lower=True, strict=None, min_length=None, max_length=None, pattern=None)]

class arbor_imago.custom_types.Gallery[source]

Bases: object

class date

Bases: object

date(year, month, day) –> date object

ctime()

Return ctime() style string.

day
classmethod fromisocalendar()

int, int, int -> Construct a date from the ISO year, week number and weekday.

This is the inverse of the date.isocalendar() function

classmethod fromisoformat(object, /)

str -> Construct a date from a string in ISO 8601 format.

classmethod fromordinal()

int -> date corresponding to a proleptic Gregorian ordinal.

classmethod fromtimestamp(timestamp, /)

Create a date from a POSIX timestamp.

The timestamp is a number, e.g. created via time.time(), that is interpreted as local time.

isocalendar()

Return a named tuple containing ISO year, week number, and weekday.

isoformat()

Return string in ISO 8601 format, YYYY-MM-DD.

isoweekday()

Return the day of the week represented by the date. Monday == 1 … Sunday == 7

max = datetime.date(9999, 12, 31)
min = datetime.date(1, 1, 1)
month
replace()

Return date with new specified fields.

resolution = datetime.timedelta(days=1)
strftime()

format -> strftime() style string.

timetuple()

Return time tuple, compatible with time.localtime().

classmethod today()

Current date or datetime: same as self.__class__.fromtimestamp(time.time()).

toordinal()

Return proleptic Gregorian ordinal. January 1 of year 1 is day 1.

weekday()

Return the day of the week represented by the date. Monday == 0 … Sunday == 6

year
description

alias of Annotated[str, StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=0, max_length=20000, pattern=None)]

folder_name

alias of str

id

alias of str

name

alias of Annotated[str, StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=256, pattern=re.compile(‘^(?!\d{4}-\d{2}-\d{2} ).*’))]

parent_id

alias of str

user_id

alias of str

visibility_level

alias of int

class arbor_imago.custom_types.GalleryDateAndName(date, name)[source]

Bases: NamedTuple

date: date | None

Alias for field number 0

name: str

Alias for field number 1

class arbor_imago.custom_types.GalleryPermission[source]

Bases: _GalleryPermissionBase

id

alias of GalleryPermissionId

class arbor_imago.custom_types.GalleryPermissionId(gallery_id, user_id)[source]

Bases: NamedTuple

gallery_id: str

Alias for field number 0

user_id: str

Alias for field number 1

class arbor_imago.custom_types.ImageFileMetadata[source]

Bases: object

file_id

alias of str

scale

alias of int

version_id

alias of str

class arbor_imago.custom_types.ImageVersion[source]

Bases: object

aspect_ratio

alias of float

average_color

alias of str

base_name

alias of Annotated[str, StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=240, pattern=re.compile(‘^(?!.*_).+$’))]

class datetime(year, month, day[, hour[, minute[, second[, microsecond[, tzinfo]]]]])

Bases: date

The year, month and day arguments are required. tzinfo may be None, or an instance of a tzinfo subclass. The remaining arguments may be ints.

astimezone()

tz -> convert to local time in new timezone tz

classmethod combine()

date, time -> datetime with same date and time fields

ctime()

Return ctime() style string.

date()

Return date object with same year, month and day.

dst()

Return self.tzinfo.dst(self).

fold
classmethod fromisoformat(object, /)

string -> datetime from a string in most ISO 8601 formats

classmethod fromtimestamp()

timestamp[, tz] -> tz’s local time from POSIX timestamp.

hour
isoformat()

[sep] -> string in ISO 8601 format, YYYY-MM-DDT[HH[:MM[:SS[.mmm[uuu]]]]][+HH:MM]. sep is used to separate the year from the time, and defaults to ‘T’. The optional argument timespec specifies the number of additional terms of the time to include. Valid options are ‘auto’, ‘hours’, ‘minutes’, ‘seconds’, ‘milliseconds’ and ‘microseconds’.

max = datetime.datetime(9999, 12, 31, 23, 59, 59, 999999)
microsecond
min = datetime.datetime(1, 1, 1, 0, 0)
minute
classmethod now(tz=None)

Returns new datetime object representing current time local to tz.

tz

Timezone object.

If no tz is specified, uses local timezone.

replace()

Return datetime with new specified fields.

resolution = datetime.timedelta(microseconds=1)
second
classmethod strptime()

string, format -> new datetime parsed from a string (like time.strptime()).

time()

Return time object with same time but with tzinfo=None.

timestamp()

Return POSIX timestamp as float.

timetuple()

Return time tuple, compatible with time.localtime().

timetz()

Return time object with same time and tzinfo.

tzinfo
tzname()

Return self.tzinfo.tzname(self).

classmethod utcfromtimestamp()

Construct a naive UTC datetime from a POSIX timestamp.

classmethod utcnow()

Return a new datetime representing UTC day and time.

utcoffset()

Return self.tzinfo.utcoffset(self).

utctimetuple()

Return UTC time tuple, compatible with time.localtime().

description

alias of Annotated[str, StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=0, max_length=20000, pattern=None)]

gallery_id

alias of str

id

alias of str

parent_id

alias of str

version

alias of Annotated[str, StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=None, max_length=None, pattern=re.compile(‘^(?!\d{2}$).+$’))]

class arbor_imago.custom_types.OTP[source]

Bases: AuthCredential

code

alias of Annotated[str, StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=6, max_length=6, pattern=re.compile(‘^\d{6}$’))]

hashed_code

alias of str

id

alias of str

class arbor_imago.custom_types.PermissionLevel[source]

Bases: object

id

alias of int

name

alias of Literal[‘editor’, ‘viewer’]

class arbor_imago.custom_types.Scope[source]

Bases: object

id

alias of int

name

alias of Literal[‘admin’, ‘users.read’, ‘users.write’]

class arbor_imago.custom_types.SignUp[source]

Bases: AuthCredential

email

alias of Annotated[EmailStr, StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=254, pattern=None)]

class arbor_imago.custom_types.User[source]

Bases: object

email

alias of Annotated[EmailStr, StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=254, pattern=None)]

hashed_password

alias of str

id

alias of str

password

alias of Annotated[str, StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=64, pattern=None)]

phone_number

alias of str

user_role_id

alias of int

username

alias of Annotated[str, StringConstraints(strip_whitespace=None, to_upper=None, to_lower=True, strict=None, min_length=3, max_length=20, pattern=re.compile(‘^[a-zA-Z0-9_.-]+$’))]

class arbor_imago.custom_types.UserAccessToken[source]

Bases: AuthCredential

id

alias of str

class arbor_imago.custom_types.UserRole[source]

Bases: object

id

alias of int

name

alias of Literal[‘admin’, ‘user’]

class arbor_imago.custom_types.VisibilityLevel[source]

Bases: object

id

alias of int

name

alias of Literal[‘public’, ‘private’]

arbor_imago.utils module

arbor_imago.utils.jwt_decode(token: str) dict[source]
arbor_imago.utils.jwt_encode(payload: dict[str, Any]) str[source]
arbor_imago.utils.send_email(recipient: Annotated[EmailStr, StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=254, pattern=None)], subject: str, body: str)[source]
arbor_imago.utils.send_sms(recipient: str, message: str)[source]

Module contents