|
1 | | -# Postal Regex |
2 | 1 |
|
3 | | -A community-maintained repository of postal/ZIP code regex patterns for 50+ countries. |
4 | | -This package is ideal for **form validation, data cleaning, and big data applications**. |
| 2 | +# Postal Regex 📨 |
| 3 | + |
| 4 | +[](https://pypi.org/project/postal-regex/) |
| 5 | +[](LICENSE) |
| 6 | +[](https://github.com/ankitgadling/postal-regex/actions) |
| 7 | + |
| 8 | +--- |
| 9 | + |
| 10 | +A community-maintained repository of postal/ZIP code regex patterns for 50+ countries. |
| 11 | +Ideal for **form validation, data cleaning, and big data applications**. |
| 12 | + |
| 13 | +--- |
| 14 | + |
| 15 | +## Table of Contents |
| 16 | + |
| 17 | +- [Features](#features) |
| 18 | +- [Installation](#installation) |
| 19 | +- [Usage](#usage) |
| 20 | +- [Big Data Support](#big-data-support) |
| 21 | +- [Contributing](#contributing) |
| 22 | +- [License](#license) |
5 | 23 |
|
6 | 24 | --- |
7 | 25 |
|
8 | 26 | ## Features |
9 | 27 |
|
10 | 28 | - ✅ 50+ countries included, with postal code regex patterns |
11 | | -- ✅ Supports lookup by **country code** or **country name** |
12 | | -- ✅ Precompiled regex for fast validation in Python |
13 | | -- ✅ JSON schema ensures consistent data structure |
14 | | -- ✅ Ready for **big data frameworks** like Spark, Dask, or Pandas |
| 29 | +- ✅ Validate postal codes by **country code** or **country name** |
| 30 | +```python |
| 31 | +from postal_regex.core import validate |
| 32 | + |
| 33 | +validate("IN", "110001") # True |
| 34 | +validate("India", "110001") # True |
| 35 | +validate("US", "12345-6789") # True |
| 36 | +```` |
| 37 | + |
| 38 | +* ✅ Normalize country identifiers |
| 39 | + |
| 40 | +```python |
| 41 | +from postal_regex.core import normalize |
| 42 | + |
| 43 | +normalize("United States") # "US" |
| 44 | +normalize("India") # "IN" |
| 45 | +``` |
| 46 | + |
| 47 | +* ✅ Works with **Pandas and Spark DataFrames** |
| 48 | + |
| 49 | +```python |
| 50 | +import pandas as pd |
| 51 | +from postal_regex.bulk import validate_dataframe |
| 52 | + |
| 53 | +df = pd.DataFrame({"country": ["US", "FR"], "postal_code": ["90210", "75001"]}) |
| 54 | +df_validated = validate_dataframe(df, country_col="country", postal_col="postal_code") |
| 55 | +print(df_validated) |
| 56 | +``` |
| 57 | + |
| 58 | +* ✅ JSON schema ensures consistent data structure |
| 59 | +* ✅ Precompiled regex for fast Python validation |
15 | 60 |
|
16 | 61 | --- |
| 62 | + |
17 | 63 | ## Installation |
18 | 64 |
|
19 | 65 | ```bash |
20 | 66 | pip install postal-regex |
21 | 67 | ``` |
22 | 68 |
|
23 | | -## Usage |
| 69 | +For development: |
24 | 70 |
|
25 | 71 | ```bash |
26 | | -from postal_regex.core import validate, normalize, get_supported_countries |
| 72 | +git clone https://github.com/ankitgadling/postal-regex.git |
| 73 | +cd postal-regex |
| 74 | +pip install -e . |
| 75 | +``` |
27 | 76 |
|
28 | | -# Validate postal codes |
29 | | -validate("IN", "110001") # True |
30 | | -validate("India", "110001") # True |
31 | | -validate("US", "12345-6789") # True |
| 77 | +--- |
| 78 | + |
| 79 | +## Big Data Support |
32 | 80 |
|
33 | | -# Normalize country identifiers |
34 | | -normalize("India") # "IN" |
35 | | -normalize("US") # "US" |
| 81 | +Validate postal codes in **large datasets** with Spark or Pandas. |
36 | 82 |
|
37 | | -# List all supported countries |
38 | | -get_supported_countries() |
39 | | -# [{'code': 'IN', 'name': 'India'}, {'code': 'US', 'name': 'United States'}, ...] |
| 83 | +### Spark Example |
40 | 84 |
|
| 85 | +```python |
| 86 | +from pyspark.sql import SparkSession |
| 87 | +from postal_regex.bulk import validate_spark_dataframe |
| 88 | + |
| 89 | +spark = SparkSession.builder.getOrCreate() |
| 90 | +df = spark.createDataFrame([ |
| 91 | + {"country": "FR", "postal_code": "75001"}, |
| 92 | + {"country": "DE", "postal_code": "10115"} |
| 93 | +]) |
| 94 | +df_validated = validate_spark_dataframe(df, country_col="country", postal_col="postal_code") |
| 95 | +df_validated.show() |
41 | 96 | ``` |
| 97 | + |
| 98 | +### Pandas Example |
| 99 | + |
| 100 | +```python |
| 101 | +import pandas as pd |
| 102 | +from postal_regex.bulk import validate_dataframe |
| 103 | + |
| 104 | +df = pd.DataFrame({ |
| 105 | + "country": ["FR", "DE"], |
| 106 | + "postal_code": ["75001", "10115"] |
| 107 | +}) |
| 108 | +df_validated = validate_dataframe(df, country_col="country", postal_col="postal_code") |
| 109 | +print(df_validated) |
| 110 | +``` |
| 111 | + |
42 | 112 | --- |
43 | 113 |
|
44 | | -## Contributors |
| 114 | +## Contributing |
| 115 | + |
| 116 | +We welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines. |
| 117 | + |
| 118 | +--- |
45 | 119 |
|
46 | | -[](https://github.com/ankitgadling/postal-regex/graphs/contributors) |
| 120 | +## License |
47 | 121 |
|
48 | | ---- |
| 122 | +MIT License. See [LICENSE](LICENSE) for details. |
0 commit comments