Validate schemas

Module contains base schema for other complex pydantic models and simple schemas to use in other places

class luna_handlers.classes.schemas.base_schema.BaseSchema(**data)[source]

Base schema model

class Config[source]

Pydantic model config

class luna_handlers.classes.schemas.base_schema.HandlerSettings[source]

Container class for service settings.

classmethod initialize(faceDescriptorVersion, bodyDescriptorVersion, livenessRealThreshold, handlersLimitsSettings, attributeStorageSettings)[source]

Initialize settings for schemas.

Parameters:
  • faceDescriptorVersion – default face descriptor version

  • bodyDescriptorVersion – default body descriptor version

  • livenessRealThreshold – default liveness threshold setting

  • handlersLimitsSettings – luna handlers limits settings

  • attributeStorageSettings – attribute storage settings

class luna_handlers.classes.schemas.base_schema.SchemaUpdaterMixin[source]

Extended base schema model.

settings

alias of HandlerSettings

classmethod update()[source]

Update inherit schema.

classmethod updateSchemas()[source]

Run settings update for inherited schemas.

Module contains schemas for attribute upgrade handler

class luna_handlers.classes.schemas.attribute_upgrade.BodyUpgradeData(**data)[source]

Body upgrade data schema

class luna_handlers.classes.schemas.attribute_upgrade.BodyUpgradePolicy(**data)[source]

Body attribute upgrade policy

class luna_handlers.classes.schemas.attribute_upgrade.FaceUpgradeData(**data)[source]

Face upgrade data schema

class luna_handlers.classes.schemas.attribute_upgrade.FaceUpgradePolicy(**data)[source]

Face attribute upgrade policy

classmethod validatePolicy(values)[source]

Validate attributes are select for extract :raises VLException(Error.NotSelectedAttributesForExtract, 400, False) if no attributes select for extract:

class luna_handlers.classes.schemas.attribute_upgrade.SamplesForUpgrade(**data)[source]

Samples for upgrade schema

classmethod validateOneOf(values)[source]

Validate one of request value:

‘face_id’ and ‘upgrade_data’ or ‘event_id’ and ‘face_upgrade_data’ and/or ‘body_upgrade_data’

Module contains schemas for conditional tags policy

class luna_handlers.classes.schemas.conditional_tags_policy.ConditionalTagsPolicy(**data)[source]

Conditional tags policy schema

execute(events)[source]

Execute additional tags policy

Parameters:

events – processing events

Return type:

None

class luna_handlers.classes.schemas.conditional_tags_policy.Tag[source]

Tag schema

Module contains schemas for detector handler

class luna_handlers.classes.schemas.detector.Detector(**data)[source]

Model for detector handler with urls or samples

static checkRequiredFaceBBox(values)[source]

Check required face bounding box for incoming image

classmethod validateHandler(values)[source]

Validate handler model

Return type:

dict

Module contains schemas for extract policy

class luna_handlers.classes.schemas.extract_policies.BaseExtractPolicy(**data)[source]

Base extract policy

class luna_handlers.classes.schemas.extract_policies.HandlerExtractPolicy(**data)[source]

Handler extract policy schema

Module contains schemas for extractor handler

class luna_handlers.classes.schemas.extractor.Extractor(**data)[source]

Model for extractor handler with samples

Module contains schemas for filters

class luna_handlers.classes.schemas.filters.AttributesFilters(**data)[source]

Matching filters schema

property isEmpty: bool

Check there is nothing to filter.

Returns:

True if all filters are equal to their defaults

Return type:

bool

isEventSatisfies(event)[source]

Does event satisfy filters by face attributes.

Parameters:

event – event

Returns:

true if event satisfied a filters otherwise false

Return type:

bool

class luna_handlers.classes.schemas.filters.ComplexFilter(**data)[source]

Complex filter - includes attributes and list of match filters

property isEmpty: bool

Check there is nothing to filter.

Returns:

True if all filters are equal to None

Return type:

bool

isEventSatisfies(event)[source]

Does an event satisfy the filters.

Parameters:

event – event

Returns:

true if event satisfied filters otherwise false

Return type:

bool

class luna_handlers.classes.schemas.filters.MatchFilter(**data)[source]

Simple match filter

property isEmpty: bool

Check there is nothing to filter.

Returns:

True if all filters are equal to their defaults

Return type:

bool

Module contains schemas for handler

class luna_handlers.classes.schemas.handler.CachedHandlerModel(**data)[source]

Cached handler model | contains minimal required fields

classmethod postInit(values)[source]

Post init

static postInitMatchPolicy(matchPolicies, accountId)[source]

Post init matching policy - apply handler account id for matching candidates :param matchPolicies: matching policies :param accountId: handler account id

Return type:

None

class luna_handlers.classes.schemas.handler.CreateHandlerModel(**data)[source]

Handler model for handler creation

classmethod validateNPostInit(values)[source]

Validate handler, post init

class luna_handlers.classes.schemas.handler.FaceInputEstimationsModel(**data)[source]

Model for incoming face estimations: urls, image or samples

classmethod validateHandler(values)[source]

Validate handler model

Return type:

dict

class luna_handlers.classes.schemas.handler.HandlerInputEstimationsModel(*, image: str = None, mimetype: str = None, face_bounding_boxes: ~types.ConstrainedListValue[~classes.schemas.simple_schemas.BoundingBoxSchema] = None, body_bounding_boxes: ~types.ConstrainedListValue[~classes.schemas.simple_schemas.BoundingBoxSchema] = None, urls: ~classes.schemas.types.userConstrainedList.<locals>.UserConstrainedList[~luna_handlers.classes.schemas.handler.UrlForInputEvent] = None, samples: ~typing.Union[~classes.schemas.types.userConstrainedList.<locals>.UserConstrainedList[~luna_handlers.classes.schemas.handler.SampleForInputEvent], ~classes.schemas.types.userConstrainedList.<locals>.UserConstrainedList[~uuid.UUID]] = None, detect_time: ~classes.schemas.types.CustomDatetime = None, detect_ts: ~classes.schemas.types.DetectTs = None, image_origin: ~classes.schemas.types.Str256 = None)[source]

Handler model for incoming estimations: urls, image(with face and/or body bounding boxes) or samples

classmethod validateHandler(values)[source]

Validate handler model

Return type:

dict

class luna_handlers.classes.schemas.handler.SampleForInputEvent(**data)[source]

Sample schema

class luna_handlers.classes.schemas.handler.UrlForInputEvent(**data)[source]

Url schema with detection time and image origin

class luna_handlers.classes.schemas.handler.ValidatorHandlerModel(**data)[source]

Handler validator model

Module contains schemas for match policy

class luna_handlers.classes.schemas.match_policy.AttributeMatchCandidates(**data)[source]

Face match candidates

class luna_handlers.classes.schemas.match_policy.BaseMatchPolicy(**data)[source]

Base match policy schema

async execute(events, luna3Client)[source]
Execute match policy:
  • filter events fo matching

  • match events’ descriptors with policy candidates

Results are stored in the input events.

Parameters:
  • events – events (references)

  • luna3Client – client

Return type:

None

classmethod targetsValidator(targets, values)[source]

Targets validator, depends on matching candidates

Return type:

Optional[List[str]]

class luna_handlers.classes.schemas.match_policy.EventMatchCandidates(**data)[source]

Event match candidates

class luna_handlers.classes.schemas.match_policy.EventMatchResult(matchingLabel, matchResult)[source]

Event match result.

candidates

match candidates

listInfo

matching list info

matchingLabel

matching label

asDict()[source]

Get Event match results without matching label as dict :returns: dict with matching candidates and matching label

Return type:

dict

class luna_handlers.classes.schemas.match_policy.FaceMatchCandidates(**data)[source]

Face match candidates

class luna_handlers.classes.schemas.match_policy.GeoPosition(**data)[source]

Geo position: longitude and latitude with deltas

class luna_handlers.classes.schemas.match_policy.MatchPolicy(**data)[source]

Match policy schema

class luna_handlers.classes.schemas.match_policy.OriginEnum(value)[source]

Match candidates origin

Module contains schemas for policies

class luna_handlers.classes.schemas.policies.HandlerConfig(facesBucket, bodiesBucket, originBucket, lunaEventsUsage, lunaSenderUsage, aggregate, useExifInfo, useAutoRotation, faceDescriptorVersion, bodyDescriptorVersion)[source]

Handler config that policies should apply.

class luna_handlers.classes.schemas.policies.Policies(**data)[source]

Policies schema

async checkListsAvailability(luna3Client, accountId)[source]

Check availability of lists from matching and link to list policies.

Parameters:
  • luna3Client – luna platform client

  • accountId – account id

Raises:

VLException(Error.ListNotFound.format(listId), 400, False), if some list is not found

Return type:

None

async execute(inputData, eventMetadata, config, luna3Client, redisContext, plugins)[source]

Execute all policies for handler.

Parameters:
  • inputData – input data (images / raw descriptors)

  • eventMetadata – user defined event metadata

  • config – handler configuration parameters

  • luna3Client – luna platform client

  • redisContext – redis context

  • plugins – plugin manager

Returns:

  • estimations in api format

  • monitoring data

Return type:

tuple[dict, HandlersMonitoringData]

getListIdsFromPolicies()[source]

Get list ids from matching and link to lists policies.

Returns:

list ids

Return type:

list[UUID]

async classmethod onShutdown()[source]

Stop Policies

async classmethod onStartup()[source]

Init Policies

prepareSDKTaskParams(config)[source]

Prepare sdk task parameters

Returns:

sdk task parameters

publishEventsToPlugins(events, plugins)[source]

Publish events to other services.

Parameters:
  • events – list of events

  • plugins – plugin manager

Return type:

None

property sdkFilters: Filters

Prepare sdk task filters

Returns:

sdk task filters

property sdkTargets: set[Union[sdk.sdk_loop.enums.LoopEstimations, app.api_sdk_adaptors.base.LoopEstimationsAlwaysOn, app.api_sdk_adaptors.base.LoopEstimationsExtended]]

Prepare sdk task targets

Returns:

sdk task targets

static validateDetectAndExtractCompatibility(detectPolicy, extractPolicy)[source]

Validate detect and extract policies compatibility

static validateDetectPolicyNotEmpty(detectPolicy)[source]

Validate non-empty detect policy

static validateGeneratedAttributesFilters(detectPolicy, extractPolicy, matchPolicies, conditionalTagsPolicies, storagePolicy)[source]

Validate attributes and detect/extract policy compatibility

static validateMatchAndExtractCompatibility(matchPolicies, extractPolicy)[source]

Validate match and extract policies compatibility

static validateMatchLabelsCompatibility(matchPolicies, conditionalTagsPolicies, storagePolicy)[source]

Validate matching label compatibility

static validateMatchPolicyUniqueLabels(matchPolicies)[source]

Validate match policy matching label uniqueness

classmethod validatePolicies(values)[source]

Execute all compatibility validators

luna_handlers.classes.schemas.policies.getObjectRecursively(data, expectedType)[source]

Recursively get object of expected type

Return type:

list[~T]

Module contains schemas for multipart requests

class luna_handlers.classes.schemas.multipart.FileNameWithBodyBBs(**data)[source]

Model for filename with body bounding boxes

class luna_handlers.classes.schemas.multipart.FileNameWithDetectionRelativeTimestamp(**data)[source]

Model for list of filename with image detect relative detection timestamp

class luna_handlers.classes.schemas.multipart.FileNameWithDetectionTime(**data)[source]

Model for list of filename with image detect time

class luna_handlers.classes.schemas.multipart.FileNameWithFaceBBs(**data)[source]

Model for filename with face bounding boxes

class luna_handlers.classes.schemas.multipart.FileNameWithImageOrigin(**data)[source]

Model for list of filename with image origin

Module contains schemas for sdk handler

class luna_handlers.classes.schemas.sdk.SDKInputEstimationsModel(**data)[source]

SDK model for incoming estimations: urls, samples or image with/without face/body bounding boxes

classmethod validateHandler(values)[source]

Validate handler model

Return type:

dict

Module contains simple schemas for multiple usage

class luna_handlers.classes.schemas.simple_schemas.BoundingBoxSchema(**data)[source]

Bounding box schema

class luna_handlers.classes.schemas.simple_schemas.UrlBboxSchema(**data)[source]

Url with face and body bounding boxes schema

class luna_handlers.classes.schemas.simple_schemas.UrlWithFaceBbox(**data)[source]

Url with face bounding boxes schema

Module contains schemas for storage policy

class luna_handlers.classes.schemas.storage_policy.AttributeStorePolicy(**data)[source]

Attribute store policy

async execute(events, luna3Client)[source]

Save attributes.

Parameters:
  • events – events

  • luna3Client – client

Return type:

None

class luna_handlers.classes.schemas.storage_policy.BodySamplePolicy(**data)[source]

Body sample policy

async execute(events, sources, bucket, luna3Client)[source]

Save body samples.

Parameters:
  • events – events

  • sources – origin image sources

  • bucket – bucket name

  • luna3Client – client

class luna_handlers.classes.schemas.storage_policy.EventStoragePolicy(**data)[source]

Event store policy

async execute(events, luna3Client, lunaEventsUsage)[source]

Save events.

Parameters:
  • events – events

  • luna3Client – client

  • lunaEventsUsage – use or not luna events

Return type:

None

async classmethod onShutdown()[source]

Stop Policies

async classmethod onStartup()[source]

Init Policies

class luna_handlers.classes.schemas.storage_policy.FaceSamplePolicy(**data)[source]

Face sample policy

async execute(events, sources, bucket, luna3Client)[source]

Save face samples.

Parameters:
  • events – events

  • sources – origin image sources

  • bucket – bucket name

  • luna3Client – client

class luna_handlers.classes.schemas.storage_policy.FaceStoragePolicy(**data)[source]

Face store policy

async execute(events, luna3Client)[source]

Execute face policy (with link to list policy).

Parameters:
  • events – processing events

  • luna3Client – luna3 client

Return type:

None

class luna_handlers.classes.schemas.storage_policy.ImageOriginPolicy(**data)[source]

Image origin policy

async execute(events, sources, bucket, luna3Client)[source]

Save origin images.

Parameters:
  • events – events

  • sources – origin image sources

  • bucket – bucket name

  • luna3Client – client

Return type:

None

class luna_handlers.classes.schemas.storage_policy.LinkToListsPolicy(**data)[source]

Link to lists policy schema

class luna_handlers.classes.schemas.storage_policy.MetaAttribute(sdkAttribute, sampleIds)[source]

Attribute.

class luna_handlers.classes.schemas.storage_policy.MetaWarp(warpedImage, sampleId=None)[source]

Warp.

sampleId

sample id

Type:

str

warpedImage

warped image

Type:

Union[bytes, FaceWarpedImage, HumanWarpedImage]

asBytes()[source]
Returns:

warp binary representation

Return type:

bytes

class luna_handlers.classes.schemas.storage_policy.NotificationStoragePolicy(**data)[source]

Notification store policy

async execute(events, redisContext, lunaSenderUsage)[source]

Save notifications :param events: events :param redisContext: redis context :param lunaSenderUsage: use or not luna sender

Return type:

None

class luna_handlers.classes.schemas.storage_policy.StoragePolicy(**data)[source]

Storage policy schema

async execute(sources, events, config, luna3Client, redisContext)[source]

Execute storage policy - save objects.

Parameters:
  • sources – origin image sources

  • events – events to process

  • config – app config

  • luna3Client – client

  • redisContext – redis context

Returns:

monitoring data

Return type:

HandlersMonitoringData

class luna_handlers.classes.schemas.storage_policy.StorePolicyConfig(facesBucket, bodiesBucket, originBucket, lunaEventsUsage, lunaSenderUsage)[source]

Handler config that policies should apply.

async luna_handlers.classes.schemas.storage_policy.saveAttributes(attributesToSave, accountId, facesClient, ttl)[source]

Save attributes.

Parameters:
  • attributesToSave – attributes

  • accountId – account id

  • facesClient – faces client

  • ttl – time to store attribute

Return type:

None

async luna_handlers.classes.schemas.storage_policy.saveSamples(warpsToSave, bucket, accountId, storeApiClient)[source]

Save warps in LIS.

Parameters:
  • warpsToSave – SDK warps to save

  • bucket – bucket name

  • accountId – account id

  • storeApiClient – image-store client

Module contains schemas for verifier

class luna_handlers.classes.schemas.verifier.VerifierAttributeStorePolicy(**data)[source]

Verifier attribute storage policy

async execute(events, luna3Client)[source]

Save attributes.

Parameters:
  • events – events

  • luna3Client – client

Return type:

None

class luna_handlers.classes.schemas.verifier.VerifierConfig(useExifInfo, useAutoRotation, faceDescriptorVersion, facesBucket)[source]

Verifier config that policies should apply.

class luna_handlers.classes.schemas.verifier.VerifierDetectPolicy(**data)[source]

Verifier detect policy

class luna_handlers.classes.schemas.verifier.VerifierExtractPolicy(**data)[source]

Verifier extract policy

class luna_handlers.classes.schemas.verifier.VerifierFaceSampleStorePolicy(**data)[source]

Verifier face sample storage policy

async execute(events, sources, bucket, luna3Client)[source]

Save face samples.

Parameters:
  • events – events

  • bucket – bucket name

  • luna3Client – client

class luna_handlers.classes.schemas.verifier.VerifierInputEstimationsModel(**data)[source]

Verifier model for incoming estimations: urls, image (only face bounding boxes available) or samples

class luna_handlers.classes.schemas.verifier.VerifierMatchPolicy(**data)[source]

Verifier match policy schema

class luna_handlers.classes.schemas.verifier.VerifierModel(**data)[source]

Verifier

class luna_handlers.classes.schemas.verifier.VerifierPoliciesModel(**data)[source]

Verifier policies

buildVerifications(matches)[source]

Build verification result in api format. :param matches: matches result

Returns:

verification result in api format

Return type:

list[dict]

async execute(inputData, config, matchPolicies, accountId, luna3Client, facesBucket)[source]

Executes given policies against provided data.

Parameters:
  • inputData – input data (images / raw descriptors)

  • config – handler configuration parameters

  • matchPolicies – MatchingPolicy instances

  • accountId – A str, account id

  • luna3Client – A luna3 client instance

  • facesBucket – faces samples bucket

Returns:

  • estimations in api format

  • monitoring data

Return type:

tuple[dict, HandlersMonitoringData]

prepareSDKTaskParams(config)[source]

Prepare sdk task parameters

Returns:

sdk task parameters

property sdkFilters: Filters

Prepare sdk task filters

Returns:

sdk task filters

property sdkTargets: set[Union[sdk.sdk_loop.enums.LoopEstimations, app.api_sdk_adaptors.base.LoopEstimationsAlwaysOn, app.api_sdk_adaptors.base.LoopEstimationsExtended]]

Prepare sdk task targets

Returns:

sdk task targets

class luna_handlers.classes.schemas.verifier.VerifierStoragePolicy(**data)[source]

Verifier storage policy

async execute(sources, events, luna3Client, facesBucket)[source]

Execute storage policy - save objects. :param sources: origin image sources :param events: events :param facesBucket: faces samples bucket :param luna3Client: luna3 client

Returns:

monitoring data

Return type:

HandlersMonitoringData

Types

Module contains custom basics for validation schemas It highly recommended to use represented classes instead of pydantic defaults!

luna_handlers.classes.schemas.types.BodyDescriptorVersion

alias of _Class

luna_handlers.classes.schemas.types.Choice(options, title='')[source]

Choice model generator :param options: available options :param title: title fo option

Returns:

Class for pydantic with choice validation

Return type:

Type[~T]

class luna_handlers.classes.schemas.types.CustomDatetime[source]

Custom extended datetime - do not use default if it needs to get attribute as str in ISO-format,

classmethod validateDatetime(value)[source]

Validate value is not string :param value: input value

Returns:

datetime in string format

Return type:

str

class luna_handlers.classes.schemas.types.CustomExtendedDatetime[source]

Custom datetime - do not use default if it needs to get attribute as str in ISO-format

classmethod initialize(storageTime)[source]

Initialize storage time :param storageTime: storage time - utc or local

classmethod validateDatetime(value)[source]

Validate value is not string :param value: input value

Returns:

datetime in string format

Return type:

str

class luna_handlers.classes.schemas.types.CustomFloat[source]

Custom float - same as default pydantic non-strict float, but not allow to use string as float

classmethod validateNonStr(value)[source]

Validate value is not string

Return type:

float

class luna_handlers.classes.schemas.types.DetectTs[source]

User-defined timestamp relative to something, such as the start of a video

luna_handlers.classes.schemas.types.FaceDescriptorVersion

alias of _Class

class luna_handlers.classes.schemas.types.Float01[source]

Non-strict float in range 0.0 - 1.0

class luna_handlers.classes.schemas.types.Float180[source]

Strict float in range -180 to 180

class luna_handlers.classes.schemas.types.FloatGeoDelta(x=0, /)[source]

Non-strict float for latitude in range 0.0 - 9.0

class luna_handlers.classes.schemas.types.FloatLatitude(x=0, /)[source]

Non-strict float for latitude in range -90.0 - 90.0

class luna_handlers.classes.schemas.types.FloatLongitude(x=0, /)[source]

Non-strict float for longitude in range -180.0 - 180.0

class luna_handlers.classes.schemas.types.GeoPosition(**data)[source]
class luna_handlers.classes.schemas.types.Int01[source]

Int in range 0 - 1

class luna_handlers.classes.schemas.types.Int02[source]

Int in range 0 - 2

class luna_handlers.classes.schemas.types.IntAge[source]

Int in range 0 - 100

class luna_handlers.classes.schemas.types.IntAngle180[source]

Int for angles - in range 0 - 180

class luna_handlers.classes.schemas.types.IntAttributeTTL[source]

Int in range 0 - MAX_ATTRIBUTE_TTL

classmethod update()[source]

Update inherit schema.

class luna_handlers.classes.schemas.types.IntEmotions[source]

Int in range of available emotions values

class luna_handlers.classes.schemas.types.IntEthnicities[source]

Int in range of available ethnicities values

class luna_handlers.classes.schemas.types.IntLiveness[source]

Int in range of available liveness state values

class luna_handlers.classes.schemas.types.IntMasks[source]

Int in range of available masks values

class luna_handlers.classes.schemas.types.IntMatchingLimit[source]

Int in range 0 - RESULT_CANDIDATE_LIMIT

classmethod update()[source]

Update inherit schema.

class luna_handlers.classes.schemas.types.IntNonNegative[source]

Int non negative

luna_handlers.classes.schemas.types.OptionalNotNullable()[source]

Pydantic hack for not required not nullable fields. If field does not present in an input json will be initialize of the None, if field is present as null in the input json will be raise corresponding error. .. rubric:: Examples

>>> class A(BaseModel):
>>>     id: int
>>>     description: str = OptionalNotNullable()
if input json is equal to `{"id": 1, "description": None}` will be raize the error.
if input json is equal to `{"id": 1}` will be correct parsing.
Returns:

Field with default None

Return type:

Any

class luna_handlers.classes.schemas.types.SDKInt[source]

Int in range from min to max SDK magic numbers

class luna_handlers.classes.schemas.types.Str128[source]

Strict string 128 len max

class luna_handlers.classes.schemas.types.Str256[source]

Strict string 128 len max

class luna_handlers.classes.schemas.types.Str36[source]

Strict string 36 len max

class luna_handlers.classes.schemas.types.StrictFloat01[source]

Strict float in range 0.0 - 1.0

class luna_handlers.classes.schemas.types.StrictFloatNonNegative[source]

Strict float non negative

luna_handlers.classes.schemas.types.getNonNullableOptionalListField(maxItems=None, minItems=None)[source]

Get non nullable optional list field - there is no default mechanism in pydantic at the moment :param maxItems: max list items :param minItems: min list items

Returns:

prepared pydantic Field

Return type:

Field

luna_handlers.classes.schemas.types.isNumber(value)[source]

Check that object is float or int :param value: object

Returns:

object

Raises:

FloatError – if object is not number

luna_handlers.classes.schemas.types.userConstrainedList(itemType, minItems=None, maxItems=None, minItemsGetter=None, maxItemsGetter=None)[source]

Create pydantic constrained list for schema validation. Update list constraints after creating a service app.

Parameters:
  • itemType – list item type

  • minItems – set min items permanently

  • maxItems – set max items permanently

  • minItemsGetter – set min items from callable object

  • maxItemsGetter – set max items from callable object

Returns:

user constrained list

Return type:

Type[List[~T]]