🎉 Thanks for taking the time to contribute! 🎉
The following is a set of guidelines for contributing to Presidio.
This project has adopted the Contributor Covenant Code of Conduct. By participating, you are expected to uphold this code. Please report unacceptable behavior to presidio@dataprivacystack.org.
Presidio is a community project aimed at helping everyone handle their private data and make the world a safer place. Presidio is both a framework and a system. It's a framework in a sense that you could take code parts from it, extend, customize and plug somewhere. It's also a system you could take as a whole or in parts and deploy locally, on-prem on in the cloud. When contributing to presidio, it's important to keep this in mind, as some "framework" contributions might not be suitable for a deployment, or vice-versa.
By submitting a contribution, you represent that you have the legal right to contribute the code and that it may be distributed under the project's MIT license. Furthermore, you confirm that you have the right to submit this contribution and that it does not knowingly contain proprietary or confidential information/code.
Commit message should be clear, explaining the committed changes.
Presidio is a library: users depend on current detection behavior. If your change alters existing behavior (for example patterns, scores, defaults, or which entities are returned) or may reduce detection accuracy, say so in the PR description and explain the trade-off. The same applies to anything that might smell like a security issue, including denial of service through regex backtracking or missing timeouts: state it and explain how it is mitigated.
Do not update CHANGELOG.md as part of your PR. Before each version bump, the
changelog entries for the current release are generated from merged PRs.
Per-PR changelog edits create unnecessary merge conflicts with other contributions.
To get started, refer to the documentation for setting up a development environment.
For Python, Presidio leverages pytest and ruff. See this tutorial on more information on testing presidio modules.
PRs require >= 90% coverage on changed lines. A bot will comment on your PR with coverage details.
Adding a new recognizer is a great way to improve Presidio. A new capability to detect a new type of PII entity improves Presidio's coverage and makes private data less accessible.
Best practices for developing recognizers are described here. Please follow these guidelines when proposing new recognizers.
To contribute a new predefined recognizer to Presidio Analyzer:
-
Choose the correct folder:
- If your recognizer is specific to a country or region, add it under
presidio-analyzer/presidio_analyzer/predefined_recognizers/country_specific/<country>/. New country directories use the full lowercase country name (south_africa,philippines). Some older directories use short forms (us,uk,thai); do not add new ones. - For globally applicable recognizers, use
generic/. - For recognizers based on NLP engines, use
nlp_engine_recognizers/. - For standalone NER models, use
ner/. - For third-party integrations, use
third_party/.
- If your recognizer is specific to a country or region, add it under
-
Add your recognizer class in the appropriate folder.
- Use ISO 639-1 language codes for
supported_language(kofor Korean, notkr). A wrong code makes the recognizer load nothing, with no error. - If your recognizer uses regex patterns:
- Make regex patterns as specific as possible to minimize false positives, and set the pattern score to how specific the pattern is on its own. Compare with existing recognizers of similar strength.
- Document the source of the pattern (the official standard, specification, or reference it comes from) and the validation algorithm if any in the class docstring.
- If your recognizer is country-specific (lives under
country_specific/<country>/):- Declare its country by setting the class-level
COUNTRY_CODE = "<iso-3166-1-alpha-2>"attribute (e.g.COUNTRY_CODE = "us"for US recognizers,"de"for Germany). This is what powersRecognizerRegistry.load_predefined_recognizers(countries=[...]). See Filtering recognizers by country for details. - The
COUNTRY_CODEvalue should match the directory's country: e.g. anything undercountry_specific/us/declares"us", anything undercountry_specific/de/declares"de". Use"uk"(not"gb") for the United Kingdom directory to stay consistent with the existing layout. - Generic / locale-agnostic recognizers (credit cards, emails, URLs, IBAN, dates, …) leave
COUNTRY_CODEunset; the default ofNonemeans the recognizer is always loaded regardless of any country filter.
- Declare its country by setting the class-level
- Use ISO 639-1 language codes for
-
Add your recognizer to the configuration:
- Add your recognizer to
presidio-analyzer/presidio_analyzer/conf/default_recognizers.yaml. - For country-specific recognizers, also declare
country_code: <iso>on the YAML entry to mirror the class-levelCOUNTRY_CODE. The loader cross-checks the two and refuses to load on mismatch, so the YAML stays a discoverable record of the country tag for no-code users. - Country-specific recognizers ship with
enabled: false. Generic recognizers may ship withenabled: trueonly when their false-positive rate is low; justify this in the PR description.
- Add your recognizer to
-
Update imports and
__all__: Export your recognizer frompresidio-analyzer/presidio_analyzer/predefined_recognizers/__init__.pyand from the country or category__init__.py, and add the class name to__all__. -
Testing:
- Ensure all existing tests pass.
- Add tests for your recognizer: assert exact scores and exact entity boundaries, include values embedded in surrounding text, include a plausible non-PII value of the same shape that must not be detected, and show that context words change the score if the recognizer defines any.
- Add at least one test that enables the recognizer in a YAML configuration and loads it through
RecognizerRegistryProvider. This is how users reach it, and it catches constructor and registration problems that direct construction hides. For non-English recognizers, set the top-levelsupported_languagesin the test configuration; it defaults to["en"]and filters other languages silently.
-
Documentation:
- Add a row for the new entity to the supported entities list.
- Follow the best practices for recognizer development and adding recognizers.
Please review the open issues on Github for known bugs and feature requests. We sometimes add 'good first issue' labels on those we believe are simpler, and 'advanced' labels on those which require more work or multiple changes across the solution.
We would love to see more samples demonstrating how to use Presidio in different scenarios. If you have a sample that you think would be useful for others, please consider contributing it. You can find the samples in the samples folder.
When contributing a sample, make sure it is self contained (e.g. external dependencies are documented), add it [to the index] (docs/samples/index.md), and to the mkdocs.yml file.
For any questions, please email presidio@dataprivacystack.org.