archivebox.tags.models

Module Contents

Classes

KVTagManager

KVTagQuerySet

Enhanced QuerySet for KVTag objects.

KVTag

Very flexible K:V tagging system that allows you to tag any model with any tag. e.g. to tag a Snapshot with 3 tags: KVTag.objects.create(obj=snapshot1, name=’tag1-simple some text’) snapshot1.tags.create(name=’tag1-simple some text’) <- this duplicate would be blocked by an IntegrityError (obj_id + name must be unique)

ModelWithKVTags

A base class for models that have tags, adds 0 additional storage overhead to models with 0 tags.

Data

FORBIDDEN_TAG_CHARS

API

archivebox.tags.models.FORBIDDEN_TAG_CHARS[source]

(‘=’, ‘\n’, ‘\t’, ‘\r’, ‘,’, “’”, ‘”’, ‘')

class archivebox.tags.models.KVTagManager[source]

Bases: django.db.models.Manager

class archivebox.tags.models.KVTagQuerySet[source]

Bases: django.db.models.QuerySet

Enhanced QuerySet for KVTag objects.

To list all unique tag names: KVTag.objects.filter(obj__created_by_id=123).names() -> {‘tag1’, ‘tag2’, ‘tag3’}

To list all the Snapshot objects with a given tag: KVTag.objects.filter(name=’tag1’).objects(Snapshot) -> QuerySet[Snapshot]: [snapshot1, snapshot2, snapshot3]

To rename a tag “abcd” to “xyz”: KVTag.objects.filter(name=’abcd’).rename(name=’xyz’) -> QuerySet[KVTag]: [xyz, xyz, xyz]

kvtags() archivebox.tags.models.KVTagQuerySet[source]
non_kvtags() archivebox.tags.models.KVTagQuerySet[source]
rename(name: str) archivebox.tags.models.KVTagQuerySet[source]
names() set[str][source]

get the unique set of names of tags in this queryset

keys() set[str][source]

get the unique set of keys of tags in this queryset

values() set[str][source]

get the unique set of values of tags in this queryset

tag_dict() dict[str, str][source]

Returns a dictionary of dictionaries, where the outer key is the obj_id and the inner key is the tag name. { ‘abcd-2345-2343-234234’: { ‘uuid’: ‘abcd-2345-2343-234234’, ‘sha256’: ‘abc123k3j423kj423kl4j23’, ‘path’: ‘/data/sources/2024-01-02_11-57-51__cli_add.txt’, ‘some-flat-tag’: None, ‘some-other-tag’: None, }, ‘efgh-2345-2343-234234’: { … }, }

model_classes() list[Type[django.db.models.Model]][source]

get the unique set of Model classes of objects in this queryset

model_class() Type[django.db.models.Model][source]

get the single Model class of objects in this queryset (or raise an error if there are multiple types)

objects(model_class: Type[django.db.models.Model] | django.contrib.contenttypes.models.ContentType | None = None) django.db.models.QuerySet[source]

Get the queryset of objects that have the tags we’ve selected (pass a Model or ContentType to filter by obj_type)

class archivebox.tags.models.KVTag[source]

Bases: ModelWithReadOnlyFields

Very flexible K:V tagging system that allows you to tag any model with any tag. e.g. to tag a Snapshot with 3 tags: KVTag.objects.create(obj=snapshot1, name=’tag1-simple some text’) snapshot1.tags.create(name=’tag1-simple some text’) <- this duplicate would be blocked by an IntegrityError (obj_id + name must be unique)

snapshot1.tags.create(name='ABID', value='snp_abc123k3j423kj423kl4j23')
snapshot1.tags.create(name='SHA256', value='1234234abc123k3j423kj423kl4j23')
snapshot1.tags.create(name='SAVE_WGET', value='False')
snapshot1.tags.create(name='URI', value='file:///data/sources/2024-01-02_11-57-51__cli_add.txt')
read_only_fields[source]

(‘id’, ‘created_at’, ‘name’, ‘value’, ‘obj_type’, ‘obj_id’)

id[source]

‘UUIDField(…)’

created_at[source]

‘AutoDateTimeField(…)’

name[source]

‘CharField(…)’

value[source]

‘TextField(…)’

obj_type[source]

‘ForeignKey(…)’

obj_id[source]

‘UUIDField(…)’

obj[source]

‘GenericForeignKey(…)’

objects: archivebox.tags.models.KVTagManager[source]

‘(…)’

class Meta[source]
db_table[source]

‘core_KVTags’

unique_together[source]

[(‘obj_id’, ‘name’)]

__str__() str[source]
__repr__() str[source]
property key: str[source]
property val: str | None[source]
property keyval_str: str[source]
static parse_keyval_str(keyval_str: str) tuple[str, str | None][source]
clean() None[source]
save(*args, **kwargs) None[source]
property slug: str[source]
property created_by_id: django.contrib.auth.models.User[source]
property created_by: django.contrib.auth.models.User[source]
class archivebox.tags.models.ModelWithKVTags[source]

Bases: ModelWithReadOnlyFields

A base class for models that have tags, adds 0 additional storage overhead to models with 0 tags.

Snapshot.objects.get(id=’…’).tags.clear() Snapshot.objects.get(id=’…’).tags.create(name=’tag1’) Snapshot.objects.get(id=’…’).tags.create(name=’tag2’, value=’some-value’) Snapshot.objects.get(id=’…’).tags.create(name=’tag3’) Snapshot.objects.get(id=’…’).tags.filter(name=’tag3’).delete() snapshot.objects.get(id=’…’).tag_names -> [‘tag1’, ‘tag2’] snapshot.objects.get(id=’…’).tag_dict -> {‘tag1’: None, ‘tag2’: ‘some-value’} snapshot.objects.get(id=’…’).tag_csv -> ‘tag1,tag2’

read_only_fields[source]

(‘id’,)

id[source]

‘UUIDField(…)’

tag_set[source]

‘GenericRelation(…)’

kvtag_set[source]

None

class Meta[source]
abstract[source]

True

content_type() django.contrib.contenttypes.models.ContentType[source]
property tag_dict: dict[str, str][source]

{ ‘⭐️’: None, ‘some-other-tag’: None, ‘some tag/testing 234[po4]’: None, ‘uuid’: ‘abcd-2345-2343-234234’, ‘sha256’: ‘abc123k3j423kj423kl4j23’, ‘file’: ‘/data/sources/2024-01-02_11-57-51__cli_add.txt’, }

get_tag_value(tag_name: str) str | None[source]

get the value of a tag with the given name pointing to this object, or None if no matching tag exists

set_tag_value(tag_name: str, tag_value: str | None) archivebox.tags.models.KVTag[source]

create or update a Tag pointing to this objects with the given name, to the given value

property tag_names: list[str][source]
property tags_csv: str[source]