---
title: "pydantic-extra-types: MAC and SHA-256 types in Python"
description: "Two changes to pydantic-extra-types in Python: MacAddress rejects octets with a sign or whitespace, and a new Sha256Str type validates SHA-256 digests."
url: "https://vulcode.com/en/opensource/contributions/pydantic-extra-types"
lang: "en"
---

[All contributions](https://vulcode.com/en/opensource/contributions)

pydantic/pydantic-extra-types

# pydantic-extra-types

Extra types for data validation in Pydantic, the popular Python library: MAC addresses, time zones, semantic versions, ULIDs and many more.

[See the repository](https://github.com/pydantic/pydantic-extra-types) [All contributions](https://vulcode.com/en/opensource/contributions)

- **Language**: Python
- **GitHub stars**: 345
- **Merged changes**: 2

## What we changed

A new Sha256Str type for SHA-256 digests, also visible in the JSON schema, and MacAddress no longer accepts octets with a plus or minus sign or whitespace.

### What this work shows

- Pydantic v2 data validation (core schema)

- JSON Schema generation

- Number parsing pitfalls in Python

- Parametrised tests in pytest

What was broken

### MacAddress accepted octets with a sign or space

validate_mac_address converted each octet with int(..., 16), which accepts a plus or minus sign and whitespace. The address -a:-b:-c:-d:-e:-f passed unchanged, and +a:+b:+c:+d:+e:+f was silently turned into 0a:0b:0c:0d:0e:0f, an address nobody provided.

How we fixed it

### An octet is exactly two hex digits

Before conversion both characters of an octet must be in string.hexdigits. Otherwise validation raises the same mac_address_format error as for other malformed octets, and new test cases cover the colon and dot formats.

[#424](https://github.com/pydantic/pydantic-extra-types/pull/424)

What was broken

### No type for a SHA-256 digest

Pydantic has a Base64Str type, but a SHA-256 digest, such as a file checksum, had to be checked with a hand-written validator. The issue asking for such a type pointed to Base64Str as the model.

How we fixed it

### Sha256Str: 64 hex characters, lowercased

The new Sha256Str type strips whitespace, lowercases the letters and requires exactly 64 hexadecimal characters. The rule is a str_schema pattern, so it also shows up in the JSON schema, and tests reject a 0x prefix and non-ASCII digits among others.

[#433](https://github.com/pydantic/pydantic-extra-types/pull/433)

## Merged changes 2

- [#433 Add Sha256Str type Merged 3 October 2026](https://github.com/pydantic/pydantic-extra-types/pull/433)

- [#424 Fix MacAddress accepting octets with a sign or whitespace Merged 5 September 2026](https://github.com/pydantic/pydantic-extra-types/pull/424)

## What it taught us

A validation gap can come from a standard function's behaviour, here int() with base 16, and only a test closes it. We build new types so the same rule applies during validation and in the generated JSON schema.

[More about this technology: Python](https://vulcode.com/en/technologies/python)

## Other projects we write code for

- [**more-itertools** Python · 4,106 stars A Python library with more routines for operating on iterables, beyond the itertools module.](https://vulcode.com/en/opensource/contributions/more-itertools)

- [**funcy** Python · 3,507 stars A collection of practical functional tools for Python, including helpers for sequences, collections and iterators.](https://vulcode.com/en/opensource/contributions/funcy)

- [**python-benedict** Python · 1,606 stars A Python dict subclass with key path access and built-in reading and writing of many formats, such as JSON, YAML, TOML and CSV.](https://vulcode.com/en/opensource/contributions/python-benedict)

- [**pydash** Python · 1,449 stars A Python utility library modelled on Lo-Dash from JavaScript. It offers ready-made operations on lists, dicts and strings in a functional style.](https://vulcode.com/en/opensource/contributions/pydash)

- [**pytimeparse** Python · 296 stars A small Python module that turns time expressions such as 1h30m or 1:24 into a number of seconds.](https://vulcode.com/en/opensource/contributions/pytimeparse)

- [**Node.js** JavaScript · 123,955 stars The JavaScript runtime built on V8 that runs servers, command line tools and front-end build pipelines. It ships a built-in node:sqlite module for working with SQLite databases.](https://vulcode.com/en/opensource/contributions/nodejs)

## Describe your project.

A free quote comes back within an hour during working hours.

### Rather skip the form?

Ask in the chat or write to us directly.

Open the chat

- **Email**: [hello@vulcode.com](mailto:hello@vulcode.com)
- **Phone**: [+48 576 043 920](tel:+48576043920)
- **Discord**: [discord.gg/vulcode](https://discord.gg/vulcode)
