Partially mask a string by replacing a given number of characters
with a fixed character. Masking can start from the beginning or end
of the string. This can be used on data of any type (numbers, longs,
and so on) and when de-identifying structured data we'll attempt to
preserve the original data's type. (This allows you to take a long
like 123 and modify it to a string like **3.
Attributes
Name
Description
masking_character
str
Character to use to mask the sensitive values—for example,
* for an alphabetic string such as a name, or 0 for
a numeric string such as ZIP code or credit card number.
This string must have a length of 1. If not supplied, this
value defaults to * for strings, and 0 for digits.
number_to_mask
int
Number of characters to mask. If not set, all matching chars
will be masked. Skipped characters do not count towards this
tally.
If number_to_mask is negative, this denotes inverse
masking. Cloud DLP masks all but a number of characters. For
example, suppose you have the following values:
- masking_character is *
- number_to_mask is -4
- reverse_order is false
- CharsToIgnore includes -
- Input string is 1234-5678-9012-3456
The resulting de-identified string is
****-****-****-3456. Cloud DLP masks all but the last
four characters. If reverse_order is true, all but
the first four characters are masked as
1234-****-****-****.
reverse_order
bool
Mask characters in reverse order. For example, if
masking_character is 0, number_to_mask is
14, and reverse_order is false, then the input
string 1234-5678-9012-3456 is masked as
00000000000000-3456. If masking_character is *,
number_to_mask is 3, and reverse_order is
true, then the string 12345 is masked as 12***.
characters_to_ignore
MutableSequence[google.cloud.dlp_v2.types.CharsToIgnore]
When masking a string, items in this list will be skipped
when replacing characters. For example, if the input string
is 555-555-5555 and you instruct Cloud DLP to skip -
and mask 5 characters with *, Cloud DLP returns
***-**5-5555.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[],[],null,["# Class CharacterMaskConfig (3.31.0)\n\nVersion latestkeyboard_arrow_down\n\n- [3.31.0 (latest)](/python/docs/reference/dlp/latest/google.cloud.dlp_v2.types.CharacterMaskConfig)\n- [3.30.0](/python/docs/reference/dlp/3.30.0/google.cloud.dlp_v2.types.CharacterMaskConfig)\n- [3.29.0](/python/docs/reference/dlp/3.29.0/google.cloud.dlp_v2.types.CharacterMaskConfig)\n- [3.28.0](/python/docs/reference/dlp/3.28.0/google.cloud.dlp_v2.types.CharacterMaskConfig)\n- [3.27.0](/python/docs/reference/dlp/3.27.0/google.cloud.dlp_v2.types.CharacterMaskConfig)\n- [3.26.0](/python/docs/reference/dlp/3.26.0/google.cloud.dlp_v2.types.CharacterMaskConfig)\n- [3.25.1](/python/docs/reference/dlp/3.25.1/google.cloud.dlp_v2.types.CharacterMaskConfig)\n- [3.24.0](/python/docs/reference/dlp/3.24.0/google.cloud.dlp_v2.types.CharacterMaskConfig)\n- [3.23.0](/python/docs/reference/dlp/3.23.0/google.cloud.dlp_v2.types.CharacterMaskConfig)\n- [3.22.0](/python/docs/reference/dlp/3.22.0/google.cloud.dlp_v2.types.CharacterMaskConfig)\n- [3.20.0](/python/docs/reference/dlp/3.20.0/google.cloud.dlp_v2.types.CharacterMaskConfig)\n- [3.19.0](/python/docs/reference/dlp/3.19.0/google.cloud.dlp_v2.types.CharacterMaskConfig)\n- [3.18.1](/python/docs/reference/dlp/3.18.1/google.cloud.dlp_v2.types.CharacterMaskConfig)\n- [3.17.0](/python/docs/reference/dlp/3.17.0/google.cloud.dlp_v2.types.CharacterMaskConfig)\n- [3.16.0](/python/docs/reference/dlp/3.16.0/google.cloud.dlp_v2.types.CharacterMaskConfig)\n- [3.15.3](/python/docs/reference/dlp/3.15.3/google.cloud.dlp_v2.types.CharacterMaskConfig)\n- [3.14.0](/python/docs/reference/dlp/3.14.0/google.cloud.dlp_v2.types.CharacterMaskConfig)\n- [3.13.0](/python/docs/reference/dlp/3.13.0/google.cloud.dlp_v2.types.CharacterMaskConfig)\n- [3.12.3](/python/docs/reference/dlp/3.12.3/google.cloud.dlp_v2.types.CharacterMaskConfig)\n- [3.11.1](/python/docs/reference/dlp/3.11.1/google.cloud.dlp_v2.types.CharacterMaskConfig)\n- [3.10.1](/python/docs/reference/dlp/3.10.1/google.cloud.dlp_v2.types.CharacterMaskConfig)\n- [3.9.2](/python/docs/reference/dlp/3.9.2/google.cloud.dlp_v2.types.CharacterMaskConfig)\n- [3.8.1](/python/docs/reference/dlp/3.8.1/google.cloud.dlp_v2.types.CharacterMaskConfig)\n- [3.7.1](/python/docs/reference/dlp/3.7.1/google.cloud.dlp_v2.types.CharacterMaskConfig)\n- [3.6.2](/python/docs/reference/dlp/3.6.2/google.cloud.dlp_v2.types.CharacterMaskConfig)\n- [3.5.0](/python/docs/reference/dlp/3.5.0/google.cloud.dlp_v2.types.CharacterMaskConfig)\n- [3.4.0](/python/docs/reference/dlp/3.4.0/google.cloud.dlp_v2.types.CharacterMaskConfig)\n- [3.3.1](/python/docs/reference/dlp/3.3.1/google.cloud.dlp_v2.types.CharacterMaskConfig)\n- [3.2.4](/python/docs/reference/dlp/3.2.4/google.cloud.dlp_v2.types.CharacterMaskConfig)\n- [3.1.1](/python/docs/reference/dlp/3.1.1/google.cloud.dlp_v2.types.CharacterMaskConfig)\n- [3.0.1](/python/docs/reference/dlp/3.0.1/google.cloud.dlp_v2.types.CharacterMaskConfig)\n- [2.0.2](/python/docs/reference/dlp/2.0.2/google.cloud.dlp_v2.types.CharacterMaskConfig)\n- [1.0.2](/python/docs/reference/dlp/1.0.2/google.cloud.dlp_v2.types.CharacterMaskConfig)\n- [0.15.2](/python/docs/reference/dlp/0.15.2/google.cloud.dlp_v2.types.CharacterMaskConfig)\n- [0.14.0](/python/docs/reference/dlp/0.14.0/google.cloud.dlp_v2.types.CharacterMaskConfig)\n- [0.13.0](/python/docs/reference/dlp/0.13.0/google.cloud.dlp_v2.types.CharacterMaskConfig)\n- [0.12.1](/python/docs/reference/dlp/0.12.1/google.cloud.dlp_v2.types.CharacterMaskConfig) \n\n CharacterMaskConfig(mapping=None, *, ignore_unknown_fields=False, **kwargs)\n\nPartially mask a string by replacing a given number of characters\nwith a fixed character. Masking can start from the beginning or end\nof the string. This can be used on data of any type (numbers, longs,\nand so on) and when de-identifying structured data we'll attempt to\npreserve the original data's type. (This allows you to take a long\nlike 123 and modify it to a string like \\*\\*3."]]