def tag_observable(
    httpreq: Request, request: ObservableTagRequest
) -> ObservableTagResponse:
    """Tags a set of observables, individually or in bulk."""
    observables = []
    for observable_id in request.ids:
        observable_obj = Observable.get(observable_id)
        if not observable_obj:
            raise HTTPException(
                status_code=400,
                detail="Tagging request contained an unknown observable: ID:{observable_id}",
            )
        observables.append(observable_obj)

    observable_tags = {}
    for observable_obj in observables:
        old_tags = [tag.name for tag in observable_obj.get_tags().values()]
        observable_obj = observable_obj.tag(request.tags, clear=request.strict)
        audit.log_timeline_tags(httpreq.state.username, observable_obj, old_tags)
        observable_tags[observable_obj.extended_id] = {
            tag.name: tag for tag in observable_obj.tags
        }

    return ObservableTagResponse(tagged=len(observables), tags=observable_tags)
Tags a set of observables, individually or in bulk.
core/web/apiv2/observables.py