Thank you for your interest in contributing! This guide will help you add new countries, maintain consistency, and ensure your contributions pass automated tests.
- Adding a New Country
- Creating an Issue
- Submitting a Pull Request
- Adding New Features
- Commit Guidelines
- Testing Your Changes
All country data is stored in src/postal_regex/data/postal_codes.json. Each entry must include:
country_code→ ISO 3166-1 alpha-2 code (2 uppercase letters)country_name→ full official country namepostal_code_regex→ regex pattern for postal/pincode validationsample_valid→ a valid postal code example for testingsample_invalid→ an invalid postal code example for testinglocal_name→ country name in local languagedescription→ brief description about postal codes
{
"country_code": "DE",
"country_name": "Germany",
"postal_code_regex": "^[0-9]{5}$",
"sample_valid": "10115",
"sample_invalid": "ABCDE",
"local_name": "Deutschland",
"description": "German postal codes (PLZ) are five digits; the first two digits denote the region."
}Tips:
- Keep formatting consistent with existing entries.
- Add one country per PR whenever possible for easier review.
If you notice missing data, incorrect regex, or want to propose a new feature:
-
Go to the Issues tab.
-
Click New Issue.
-
Use a clear and descriptive title, e.g.,
Add postal code regex for Japan. -
Include details:
- Country name and ISO code
- Example valid and invalid postal codes
- Reference for regex pattern (official sources preferred)
Example Issue:
Title: Add postal code regex for Japan
Body:
Country: Japan (JP)
Sample Valid: 100-0001
Sample Invalid: ABC-123
Reference: https://www.example.com/japan-postal-codes
-
Fork the repository and create a new branch:
git checkout -b add-japan-postal-code
-
Add your country entry to
src/postal_regex/data/postal_codes.json. -
Run Python tests locally:
pytest
-
Lint your code and JSON files:
flake8 . python -m json.tool src/postal_regex/data/postal_codes.json -
Commit your changes using Conventional Commits.
-
Push your branch and create a PR against the
mainbranch.
PR Template:
### Added
- Postal code regex for Japan (JP)
### Validation
- sample_valid: 100-0001
- sample_invalid: ABC-123
Contributors can propose or implement improvements beyond adding countries:
Steps to contribute a feature:
- Create an Issue describing the feature and its purpose.
- Fork the repo and create a feature branch:
git checkout -b feat/your-feature- Implement the feature and write tests.
- Format and lint your code:
black .
flake8 .- Commit using Conventional Commits:
feat: add [short description]
- Push and open a PR with a clear description and test results.
Use Conventional Commits:
| Type | When to use |
|---|---|
feat |
Adding a new country or feature |
fix |
Correcting a regex or invalid entry |
docs |
Updating README or contribution guides |
test |
Adding or fixing test cases |
chore |
Maintenance tasks, formatting, or minor edits |
Example Commit Messages:
feat: add postal code regex for Japan (JP)
fix: correct regex for Germany (DE) postal code
docs: update contributing guide with PR instructions
test: add test case for UK postal code
- Validate your regex with Python
remodule. - Ensure JSON is properly formatted:
python -m json.tool src/postal_regex/data/postal_codes.json- Run all tests using
pytest:
pytest- Format and lint your code to maintain consistency and catch potential issues:
# Automatically format your code
black .
# Check for style issues, errors, and potential problems
flake8 .Notes:
blackenforces consistent code formatting automatically.flake8helps catch style violations, undefined names, or other issues thatblackdoesn’t fix.- Running both ensures that your code is clean, consistent, and ready for review.
✅ Following this guide ensures smooth contributions, consistent formatting.