---
source: https://iinventedlight.com/library/notes/python-fnmatch.md
title: "Python fnmatch - glob-style name matching with *, ? and brackets"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "PSF-2.0 (Python docs); PSF-2.0 (python/cpython (GitHub)); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Python docs, fnmatch - Unix filename pattern matching; python/cpython (GitHub), Lib/fnmatch.py. PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-18
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-18
as_of: 2026-11-18
confidence: medium
untested: "Not reproduced (2026-11-18). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-python: fnmatch"
tags: [python, fnmatch, glob, wildcards, stdlib]
client: Librarian
sources:
  - id: S1
    title: "fnmatch - Unix filename pattern matching"
    publisher: Python docs
    url: https://docs.python.org/3/library/fnmatch.html
    accessed: 2026-11-18
    license: "PSF-2.0"
  - id: S2
    title: "Lib/fnmatch.py"
    publisher: python/cpython (GitHub)
    url: https://github.com/python/cpython/blob/main/Lib/fnmatch.py
    accessed: 2026-11-18
    license: "PSF-2.0"
---
# Python fnmatch - glob-style name matching with *, ? and brackets
**Answer:** This module provides support for Unix shell-style wildcards. `fnmatch(filename, pattern)` matches according to the local convention, and `translate(PATTERN)` returns a regular expression corresponding to PATTERN.

## Examples

```python
import fnmatch, os

fnmatch.fnmatch("README.md", "*.md")          # True
fnmatch.fnmatchcase("README.md", "*.MD")      # False on a case-sensitive match
fnmatch.filter(os.listdir("."), "test_*.py")
print(fnmatch.translate("*.pyc"))             # regular expression
```

## Rules

- `*` matches everything, `?` matches a single character, and brackets match a character class.
- `fnmatchcase` is a case-sensitive variant. `filter(names, pattern)` returns the matching names.

## See also

- [python-pathlib](https://iinventedlight.com/library/notes/python-pathlib/)
- [python-regex-basics](https://iinventedlight.com/library/notes/python-regex-basics/)

## Claims

- id: C1
  claim: fnmatch supports Unix shell-style wildcards.
  source: S1
  evidence: "This module provides support for Unix shell-style wildcards"

- id: C2
  claim: translate converts a pattern to a regular expression.
  source: S2
  evidence: "translate(PATTERN) returns a regular expression corresponding to PATTERN"

- id: C3
  claim: fnmatch matches a filename to a pattern.
  source: S2
  evidence: "fnmatch(FILENAME, PATTERN) matches according to the local convention"

## Sources

- [S1] fnmatch - Unix filename pattern matching. Python docs. https://docs.python.org/3/library/fnmatch.html . License: PSF-2.0. Accessed 2026-11-18.

- [S2] Lib/fnmatch.py. python/cpython (GitHub). https://github.com/python/cpython/blob/main/Lib/fnmatch.py . License: PSF-2.0. Accessed 2026-11-18.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python docs, fnmatch - Unix filename pattern matching; python/cpython (GitHub), Lib/fnmatch.py. PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
