---
title: enum | CodeWeaver Docs
description: API reference for codeweaver.core.types.enum
url: "https://docs.knitli.com/api/core/types/enum"
type: static
generatedAt: "2026-04-17T17:21:08.178Z"
---

# enum
       [Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Ftypes%2Fenum%2F.%20I%20want%20to%20ask%20questions%20about%20it.)[Open in Claude](https://claude.ai/new?q=Read%20https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Ftypes%2Fenum%2F.%20I%20want%20to%20ask%20questions%20about%20it.)[View in Markdown](/codeweaver/api/core/types/enum.md)       [Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Ftypes%2Fenum%2F)[Share on X](https://x.com/intent/tweet?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Ftypes%2Fenum%2F&text=enum)[Share on Threads](https://threads.net/intent/post?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Ftypes%2Fenum%2F&text=enum)[Share on Bluesky](https://bsky.app/intent/compose?text=enum%20https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Ftypes%2Fenum%2F)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Ftypes%2Fenum%2F)[Share on Reddit](https://reddit.com/submit?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Ftypes%2Fenum%2F&title=enum)[Share on Hacker News](https://news.ycombinator.com/submitlink?u=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Ftypes%2Fenum%2F&t=enum)[Share on Email](mailto:?subject=enum&body=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Ftypes%2Fenum%2F)[Share on WhatsApp](https://wa.me/?text=enum%20https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Ftypes%2Fenum%2F)[Share on Telegram](https://t.me/share/url?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Ftypes%2Fenum%2F&text=enum)
# `codeweaver.core.types.enum`
[Section titled “codeweaver.core.types.enum”](#codeweavercoretypesenum)
Base enum classes for the CodeWeaver project.

## Class: `AnonymityConversion`
[Section titled “Class: AnonymityConversion”](#class-anonymityconversion)
Enumeration of anonymity conversion methods for telemetry data.

These methods define how telemetry data should be anonymized or aggregated to protect user privacy. Only applies to filtered fields.

### Method: `filtered`
[Section titled “Method: filtered”](#method-filtered)

**

```
filtered()
```

Process values according to the anonymity conversion method.

## Class: `BaseDataclassEnum`
[Section titled “Class: BaseDataclassEnum”](#class-basedataclassenum)
A base enum class for enums with dataclass members. Does not come with its ‘type’ — you must define that with `codeweaver.core.types.dataclasses.BaseEnumData` and subclass your implementation.

## Usage
[Section titled “Usage”](#usage)
Building a dataclass enum is a bit more involved than a standard enum. Steps:

 1. Create a dataclass. It should inherit from `codeweaver.core.types.dataclasses.BaseEnumData`.
 - Note that `BaseEnumData` already includes `aliases`, and `description` fields, so you don’t need to redefine those unless you want to customize them. `_name` and `_value` are required by `Enum` members, **you cannot use those names or their non-sunder versions (i.e. ‘name’)**. `_name` will be the name of the Enum member you assign in the class definition, and `_value` *is your dataclass instance*.
 - It is already a dataclass and does not need a `@dataclass` decorator (which will break it).
 - Suggestion: I find that it’s easiest to define a dataclass-within-a-dataclass, where there is only a single top-level field that is either a typed dict, dataclass or named tuple. It makes constructing the dataclass enum members easier to read.
 1. Create your enum class, inheriting from `BaseDataclassEnum`.
 1. Define your enum members, assigning each to an instance of your dataclass.
 1. Use it.

## Example
[Section titled “Example”](#example)

**

```
from codeweaver.core import BaseEnumData, BaseDataclassEnum
class ColorData(BaseEnumData):    hex_code: str    rgb: tuple[int, int, int]
    # Because we are making a serializable dataclass with pydantic,    # we *must* define __init__ and set values before calling super().__init__()    def __init__(self, hex_code: str, rgb: tuple[int, int, int], *args: Any):        # use `object.__setattr__` to avoid pydantic/dataclass immutability issues        # it's a hack, but it works. We're not abusing it, just working around limitations.        object.__setattr__(self, "hex_code", hex_code)        object.__setattr__(self, "rgb", rgb)        # now call and validate        super().__init__(*args)
class Color(ColorData, BaseDataclassEnum):    # Important: aliases and description are optional *positional* args after the required fields.    RED = ColorData(hex_code="#FF0000", rgb=(255, 0, 0), ("rojo", "rouge"), "A bright red color.")    GREEN = ColorData(hex_code="#00FF00", rgb=(0, 255, 0))    BLUE = ColorData(hex_code="#0000FF", rgb=(0, 0, 255))
    # define methods/properties if you want    @property    def brightness(self) -&gt; float:        r, g, b = self.value.rgb        return (r + g + b) / (3 * 255)
print(Color.RED.value.hex_code)  # Output: #FF0000print(Color.GREEN.variable)      # Output: greenprint(Color.BLUE.as_title)       # Output: Blue
```

### Method: `add_alias`
[Section titled “Method: add_alias”](#method-add_alias)

**

```
add_alias()
```

Add an alias to the enum member.

### Method: `add_member`
[Section titled “Method: add_member”](#method-add_member)

**

```
add_member()
```

Dynamically add a new member to the enum.

### Method: `from_string`
[Section titled “Method: from_string”](#method-from_string)

**

```
from_string()
```

Convert a string to the corresponding enum member.

### Method: `get_aliases`
[Section titled “Method: get_aliases”](#method-get_aliases)

**

```
get_aliases()
```

Return a mapping of aliases to enum members.

### Method: `members`
[Section titled “Method: members”](#method-members)

**

```
members()
```

Return all members of the enum as a tuple.

### Method: `values`
[Section titled “Method: values”](#method-values)

**

```
values()
```

Return all enum member values as a tuple.

## Class: `BaseEnum`
[Section titled “Class: BaseEnum”](#class-baseenum)
An enum class that provides common functionality for all enums in the CodeWeaver project. Enum members must be unique and either all strings or all integers.

`add_enum_member` allows us to dynamically add members, such as for plugin systems.

BaseEnum provides convenience methods for converting between strings and enum members, checking membership, and retrieving members and members’ values, and adding new members dynamically.

### Method: `add_alias`
[Section titled “Method: add_alias”](#method-add_alias-1)

**

```
add_alias()
```

Add an alias to the enum member.

### Method: `add_member`
[Section titled “Method: add_member”](#method-add_member-1)

**

```
add_member()
```

Dynamically add a new member to the enum.

### Method: `aliases`
[Section titled “Method: aliases”](#method-aliases)

**

```
aliases()
```

Provides a way to identify alternate names for a member, used in string conversion and identification.

### Method: `from_string`
[Section titled “Method: from_string”](#method-from_string-1)

**

```
from_string()
```

Convert a string to the corresponding enum member. Flexibly handles different cases, dashes vs underscores, and some common variations.

`from_string` assumes that it’s usually getting valid input, so it tries to find a match in several ways before giving up and raising a `ValueError`. We’re taking a “people are messy” approach here to make it easier to work with user settings. There are probably some unknown edge cases that could cause problems, such as when two members have very similar names, but we can address those as they arise (for example, if ‘JAVA’ didn’t match on its value or name for some reason (won’t happen), then the heuristic here could assign it to “JAVASCRIPT” as a last resort).

### Method: `is_member`
[Section titled “Method: is_member”](#method-is_member)

**

```
is_member()
```

Check if a value is a member of the enum.

### Method: `members`
[Section titled “Method: members”](#method-members-1)

**

```
members()
```

Return all members of the enum as a tuple.

### Method: `members_to_values`
[Section titled “Method: members_to_values”](#method-members_to_values)

**

```
members_to_values()
```

Return a dictionary mapping member names to their values.

### Method: `serialize_for_cli`
[Section titled “Method: serialize_for_cli”](#method-serialize_for_cli)

**

```
serialize_for_cli()
```

Serialize the enum member for CLI display.

### Method: `values`
[Section titled “Method: values”](#method-values-1)

**

```
values()
```

Return all enum member names as a tuple.