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

classmethod alias_generator(paramName)[source]

Generate aliases :param paramName: model field name

Return type:str
asDict()[source]

Get data from initialized model :returns: dict with snake_case keys

Return type:dict
luna_handlers.classes.schemas.base_schema.replaceEqualSuffix(snakeCaseName)[source]

Replace gt/gte/lt/lte suffix contains one underline with two underlines :param snakeCaseName: key in snake_case

Return type:str

Module contains schemas for attribute upgrade handler

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

Model for ‘face attribute upgrade handler’ (upgrade face’s attributes from samples)

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

classmethod validateOneOf(values)[source]

Validate one of

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

isEmpty

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

isAttributeFiltersEmpty

Check there is no attributes to filter.

Returns:True if all filters are equal to None
Return type:bool
isEmpty

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

isEmpty

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.BaseInputEstimationsModel(**data)[source]

Base model for incoming estimations: urls, image or samples

classmethod validateImageMimetype(mimetype)[source]

Validate image mimetype :param value: mimetype string

Returns:string with valid mimetype
Raises:ValueError(f”{value} is not allowed image mimetype”) if mimetype is not allowed
Return type:str
classmethod validateOneOf(values)[source]

Validate one of

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.HandlerInputEstimationsModel(**data)[source]

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

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

Handler model for handler usage

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
classmethod validateNPostInit(values)[source]

Validate handler, post init

Module contains schemas for match policy

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 .. attribute:: 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

areFiltersEmpty()[source]

Are match filters empty

Return type:bool
classmethod candidatesValidator(candidates)[source]

Candidates validator, depends on matching candidates | better validation errors

Return type:dict
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.OriginEnum[source]

Match candidates origin

Module contains schemas for policies

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

Policies schema

static enrichEventsWithMetadata(events, source, tags, userData, detectTime, externalId, location, trackId=None)[source]

Enrich processing event with metadata.

Parameters:
  • events – events
  • source – event source
  • tags – event tags
  • userData – user data
  • detectTime – detection time
  • externalId – event external id
  • location – event location
  • trackId – (str) event track id
Return type:

None

execute(accountId, inputData, sdkLoop, luna3Client, aggregate, userData, externalId, source, userDefinedTags, location, logger, eventTime, handlerId, trackId, plugins, redisContext, facesBucket, bodiesBucket, originBucket, lunaEventsUsage, lunaSenderUsage)[source]

Execute all policies for handler.

Parameters:
  • accountId – account id
  • inputData – a list of input images (or warps) or descriptors
  • sdkLoop – sdk loop
  • luna3Client – luna platform client
  • aggregate – aggregate all extracted samples to one or not
  • userData – user data for created faces
  • externalId – external id for created faces
  • source – user-defined source
  • userDefinedTags – user-defined tags
  • location – user-defined location
  • logger – logger
  • eventTime – event time
  • handlerId – handler id
  • trackId – event track id
  • plugins – plugin manager
  • redisContext – redis context
  • facesBucket – faces sample bucket
  • bodiesBucket – bodies sample bucket
  • originBucket – origin image bucket
  • lunaEventsUsage – luna events usage
  • lunaSenderUsage – luna sender usage
Returns:

tuple, first - all detection, second - events, third - monitoring data

Raises:

VLException(Error.AggregationNotSupported) if aggregate flag enabled and raw descriptor data received

Return type:

Tuple[List[dict], List[Event], Dict[str, List[dict]], DataForMonitoring]

classmethod onShutdown()[source]

Stop Policies

classmethod onStartup()[source]

Init Policies

prepareSDKTask(sdkData, aggregate)[source]

Prepare sdk task :param sdkData: a list of input images or warps :param aggregate: aggregate all extracted samples to one or not

Returns:sdk task
Return type:SDKTask
publishEvents(events, handlerId, eventTime, plugins, redisContext, logger, accountId, lunaSenderUsage)[source]

Publish events to other services.

Parameters:
  • events – list of events
  • handlerId – handler id
  • eventTime – event time
  • plugins – plugin manager
  • redisContext – redis context
  • logger – logger
  • accountId – account id
  • lunaSenderUsage – luna sender usage
Return type:

None

static validateBasicAttributesFilters(extractPolicy, matchPolicies, conditionalTagsPolicies, storagePolicy)[source]

Validate basic attributes and extract policy compatibility

static validateDetectAndExtractCompatibility(detectPolicy, extractPolicy)[source]

Validate detect and extract policies compatibility

static validateDetectPolicyNotEmpty(detectPolicy)[source]

Validate non-empty detect policy

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.getImagesReplyData(sdkData, images, extractExif)[source]

Get images’ processing data in reply format.

Parameters:
  • sdkData – sdk data
  • images – images
  • extractExif – whether to extract exif
Returns:

list of images with status, filename, etc

Return type:

List[dict]

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

Recursively get object of expected type

Return type:list

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.FileNameWithFaceBBs(**data)[source]

Model for filename with face bounding boxes

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 validateOneOf(values)[source]

Validate one of

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.UrlSchema(**data)[source]

Url with bounding boxes schema

Module contains schemas for storage policy

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

Attribute store policy

execute(events, accountId, luna3Client)[source]

Save attributes.

Parameters:
  • events – events
  • accountId – account id
  • luna3Client – client
Return type:

None

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

Body sample policy

execute(events, bucket, accountId, luna3Client)[source]

Save body samples.

Parameters:
  • events – events
  • bucket – bucket name
  • accountId – account id
  • luna3Client – client
Return type:

None

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

Event store policy

execute(logger, events, luna3Client, eventTime, accountId, handlerId, lunaEventsUsage)[source]

Save events.

Parameters:
  • logger – logger
  • events – events
  • luna3Client – client
  • eventTime – event create time
  • accountId – account id
  • handlerId – handler id
  • lunaEventsUsage – use or not luna events
Return type:

None

classmethod onShutdown()[source]

Stop Policies

classmethod onStartup()[source]

Init Policies

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

Face sample policy

execute(events, bucket, accountId, luna3Client)[source]

Save face samples.

Parameters:
  • events – events
  • bucket – bucket name
  • accountId – account id
  • luna3Client – client
Return type:

None

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

Face store policy

execute(events, accountId, luna3Client, userData='', externalId=None)[source]

Execute face policy (with link to list policy).

Parameters:
  • events – processing events
  • accountId – account id
  • luna3Client – luna3 client
  • userData – user data for all faces
  • externalId – external for all faces
Return type:

None

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

Image origin policy

execute(events, bucket, accountId, luna3Client, originImages)[source]

Save origin images.

Parameters:
  • events – events
  • bucket – bucket name
  • accountId – account id
  • luna3Client – client
  • originImages – list of input images
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.StoragePolicy(**data)[source]

Storage policy schema

execute(events, accountId, luna3Client, originImages, userData, externalId, logger, eventTime, handlerId, facesBucket, bodiesBucket, originBucket, lunaEventsUsage)[source]

Execute storage policy - save objects.

Parameters:
  • events – events to process
  • accountId – account id
  • luna3Client – client
  • originImages – data with origin images
  • userData – user data
  • externalId – external id
  • logger – logger
  • eventTime – event create time
  • handlerId – handler id
  • facesBucket – faces samples bucket
  • bodiesBucket – bodies samples bucket,
  • originBucket – origin image bucket,
  • lunaEventsUsage – luna events usage
Returns:

monitoring data

Return type:

DataForMonitoring

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
Return type:

List[str]

Module contains schemas for verifier

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

Verifier attribute storage policy

execute(events, accountId, luna3Client)[source]

Save attributes.

Parameters:
  • events – events
  • accountId – account id
  • luna3Client – client
Return type:

None

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

execute(events, bucket, accountId, luna3Client)[source]

Save face samples.

Parameters:
  • events – events
  • bucket – bucket name
  • accountId – account id
  • luna3Client – client
Return type:

None

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.VerifierModel(**data)[source]

Verifier

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

Verifier policies

execute(accountId, inputData, sdkLoop, luna3Client, logger, matchPolicies, facesBucket)[source]

Executes given policies against provided data.

Parameters:
  • accountId – A str, account id
  • inputData – A list of images/descriptors
  • sdkLoop – A sdk loop instance
  • luna3Client – A luna3 client instance
  • logger – A Logger instance
  • matchPolicies – MatchingPolicy instances
  • facesBucket – faces samples bucket
Returns:

tuple, first - all detection, second - events, third - monitoring data

Return type:

Tuple[List[dict], List[Event], Dict[str, List[dict]], DataForMonitoring]

prepareSDKTask(sdkData, aggregate)[source]

Prepare sdk task :param sdkData: a list of input images or warps :param aggregate: aggregate all extracted samples to one or not

Returns:sdk task
Return type:SDKTask
class luna_handlers.classes.schemas.verifier.VerifierStoragePolicy(**data)[source]

Verifier storage policy

execute(events, accountId, luna3Client, facesBucket)[source]

Execute storage policy - save objects. :param events: events :param accountId: account id :param luna3Client: luna 3 client :param facesBucket: faces samples bucket

Returns:monitoring data
Return type:DataForMonitoring

Types

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

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 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

value

input value

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.Float01[source]

Non-strict float in range 0.0 - 1.0

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

Non-strict float for latitude in range 0.0 - 9.0

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

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

class luna_handlers.classes.schemas.types.FloatLongitude[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

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.IntMasks[source]

Int in range of available masks values

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

Int in range 0 - MAX_MATCHING_LIMIT

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]

Non-strict float in range 0.0 - 1.0

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:<cyfunction Field at 0x7f989b3a7750>
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