pyap2 0.2.20__tar.gz → 0.3.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pyap2-0.3.1/.gitignore ADDED
@@ -0,0 +1,26 @@
1
+ # Compiled python modules.
2
+ *.pyc
3
+
4
+ # Setuptools distribution folder.
5
+ /dist/
6
+ /build/
7
+
8
+ # Python egg metadata, regenerated from source files by setuptools.
9
+ /*.egg-info
10
+
11
+ # Coverage reports
12
+ /htmlcov
13
+ /__pycache__
14
+ .coverage
15
+
16
+ # Venvs
17
+ /venv*
18
+ /.venv
19
+
20
+ # Misc
21
+ run.py
22
+ todo.txt
23
+ .DS_Store
24
+ .tox
25
+ files.txt
26
+ .vscode
@@ -0,0 +1,10 @@
1
+ Argyle's Pyap fork is developed by
2
+ - `<https://github.com/DeviousStoat>`_
3
+ - `<https://github.com/lmelninkas>`_
4
+
5
+ Initial Authors of Pyap
6
+ ```````````````````````
7
+ - `Vladimir Goncharov <https://github.com/vladimarius>`_
8
+ - `Thomas Bird <https://github.com/thomasbird>`_ (British parsing rules)
9
+ - `Thomas Funk <https://github.com/tomfunk>`_ (thomasfunk10@gmail.com)
10
+ - `KCzar <https://github.com/KCzar>`_
@@ -1,27 +1,24 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.5
2
2
  Name: pyap2
3
- Version: 0.2.20
4
- Summary: Pyap2 is a maintained fork of pyap, a regex-based library for parsing US, CA, and UK addresses. The fork adds typing support, handles more address formats and edge cases.
5
- Home-page: https://github.com/argyle-engineering/pyap
6
- License: MIT
3
+ Version: 0.3.1
4
+ Summary: A maintained, typed fork of pyap for parsing US, CA, and UK addresses
5
+ Project-URL: Documentation, https://github.com/argyle-engineering/pyap
6
+ Project-URL: Homepage, https://github.com/argyle-engineering/pyap
7
+ Project-URL: Repository, https://github.com/argyle-engineering/pyap
8
+ Author-email: Argyle Developers <developers@argyle.io>
9
+ License-Expression: MIT
10
+ License-File: LICENSE
7
11
  Keywords: address,parser,regex
8
- Author: Argyle Developers
9
- Author-email: developers@argyle.io
10
- Requires-Python: >=3.9,<4.0
11
- Classifier: License :: OSI Approved :: MIT License
12
12
  Classifier: Operating System :: OS Independent
13
13
  Classifier: Programming Language :: Python :: 3
14
- Classifier: Programming Language :: Python :: 3.9
15
- Classifier: Programming Language :: Python :: 3.10
16
- Classifier: Programming Language :: Python :: 3.11
17
- Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3 :: Only
18
15
  Classifier: Programming Language :: Python :: 3.11
19
- Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.12
20
17
  Classifier: Topic :: Scientific/Engineering :: Information Analysis
21
18
  Classifier: Topic :: Software Development :: Libraries
22
19
  Classifier: Topic :: Utilities
23
- Project-URL: Documentation, https://github.com/argyle-engineering/pyap
24
- Project-URL: Repository, https://github.com/argyle-engineering/pyap
20
+ Classifier: Typing :: Typed
21
+ Requires-Python: >=3.11
25
22
  Description-Content-Type: text/x-rst
26
23
 
27
24
  Pyap2: Python address parser
@@ -55,17 +52,41 @@ detecting and parsing addresses. Currently it supports US 🇺🇸, Canadian
55
52
  Installation
56
53
  ------------
57
54
 
58
- To install Pyap2, simply:
55
+ Pyap2 requires Python 3.11 or newer. To install it:
59
56
 
60
57
  .. code-block:: bash
61
58
 
62
59
  $ pip install pyap2
63
60
 
64
61
 
62
+ Development
63
+ -----------
64
+
65
+ Install the project and its development tools from the lock file:
66
+
67
+ .. code-block:: bash
68
+
69
+ $ uv sync --locked --all-groups
70
+
71
+ Run the same checks used by CI:
72
+
73
+ .. code-block:: bash
74
+
75
+ $ uv run task check
76
+
77
+ Individual tasks include ``lint``, ``check_fmt``, ``check_types``, ``fmt``, and
78
+ ``test``. For example:
79
+
80
+ .. code-block:: bash
81
+
82
+ $ uv run task fmt
83
+ $ uv run task test
84
+
85
+
65
86
 
66
87
  About
67
88
  -----
68
- We started improving the original `pyap` by adopting poetry and adding typing support.
89
+ We started improving the original `pyap` by adopting modern packaging and adding typing support.
69
90
  It was extensively tested in web-scraping operations on thousands of US addresses.
70
91
  Gradually, we added support for many rarer address formats and edge cases, as well
71
92
  as the ability to parse a partial address where only street info is available.
@@ -99,4 +120,3 @@ and a state name abbreviation "IN" (Indiana).
99
120
  The good news is that the above mentioned errors are **quite rare**.
100
121
 
101
122
 
102
-
@@ -29,17 +29,41 @@ detecting and parsing addresses. Currently it supports US 🇺🇸, Canadian
29
29
  Installation
30
30
  ------------
31
31
 
32
- To install Pyap2, simply:
32
+ Pyap2 requires Python 3.11 or newer. To install it:
33
33
 
34
34
  .. code-block:: bash
35
35
 
36
36
  $ pip install pyap2
37
37
 
38
38
 
39
+ Development
40
+ -----------
41
+
42
+ Install the project and its development tools from the lock file:
43
+
44
+ .. code-block:: bash
45
+
46
+ $ uv sync --locked --all-groups
47
+
48
+ Run the same checks used by CI:
49
+
50
+ .. code-block:: bash
51
+
52
+ $ uv run task check
53
+
54
+ Individual tasks include ``lint``, ``check_fmt``, ``check_types``, ``fmt``, and
55
+ ``test``. For example:
56
+
57
+ .. code-block:: bash
58
+
59
+ $ uv run task fmt
60
+ $ uv run task test
61
+
62
+
39
63
 
40
64
  About
41
65
  -----
42
- We started improving the original `pyap` by adopting poetry and adding typing support.
66
+ We started improving the original `pyap` by adopting modern packaging and adding typing support.
43
67
  It was extensively tested in web-scraping operations on thousands of US addresses.
44
68
  Gradually, we added support for many rarer address formats and edge cases, as well
45
69
  as the ability to parse a partial address where only street info is available.
@@ -3,6 +3,7 @@
3
3
  """
4
4
  API hooks
5
5
  """
6
+
6
7
  from .api import parse, parse_single_street
7
8
  from .utils import match, findall
8
9
  from .address import Address
@@ -1,14 +1,14 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  """
4
- pyap.address
5
- ~~~~~~~~~~~~~~~~
4
+ pyap.address
5
+ ~~~~~~~~~~~~~~~~
6
6
 
7
- Contains class for constructing Address object which holds information
8
- about address and its components.
7
+ Contains class for constructing Address object which holds information
8
+ about address and its components.
9
9
 
10
- :copyright: (c) 2015 by Vladimir Goncharov.
11
- :license: MIT, see LICENSE for more details.
10
+ :copyright: (c) 2015 by Vladimir Goncharov.
11
+ :license: MIT, see LICENSE for more details.
12
12
  """
13
13
 
14
14
  from dataclasses import dataclass, asdict
@@ -1,13 +1,13 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  """
4
- pyap.api
5
- ~~~~~~~~~~~~~~~~
4
+ pyap.api
5
+ ~~~~~~~~~~~~~~~~
6
6
 
7
- This module contains address parser API functions.
7
+ This module contains address parser API functions.
8
8
 
9
- :copyright: (c) 2015 by Vladimir Goncharov.
10
- :license: MIT, see LICENSE for more details.
9
+ :copyright: (c) 2015 by Vladimir Goncharov.
10
+ :license: MIT, see LICENSE for more details.
11
11
  """
12
12
 
13
13
  from typing import Literal, List
@@ -1,13 +1,13 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  """
4
- pyap.exceptions
5
- ~~~~~~~~~~~~~~~~
4
+ pyap.exceptions
5
+ ~~~~~~~~~~~~~~~~
6
6
 
7
- This module contains address parser exceptions.
7
+ This module contains address parser exceptions.
8
8
 
9
- :copyright: (c) 2015 by Vladimir Goncharov.
10
- :license: MIT, see LICENSE for more details.
9
+ :copyright: (c) 2015 by Vladimir Goncharov.
10
+ :license: MIT, see LICENSE for more details.
11
11
  """
12
12
 
13
13
 
@@ -1,14 +1,14 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  """
4
- pyap.parser
5
- ~~~~~~~~~~~~~~~~
4
+ pyap.parser
5
+ ~~~~~~~~~~~~~~~~
6
6
 
7
- This module contains AddressParser class which connects all the
8
- functionality of the package in one place.
7
+ This module contains AddressParser class which connects all the
8
+ functionality of the package in one place.
9
9
 
10
- :copyright: (c) 2015 by Vladimir Goncharov.
11
- :license: MIT, see LICENSE for more details.
10
+ :copyright: (c) 2015 by Vladimir Goncharov.
11
+ :license: MIT, see LICENSE for more details.
12
12
  """
13
13
 
14
14
  import re
@@ -32,13 +32,13 @@ class AddressParser:
32
32
  self.rules = data.full_address
33
33
  self.single_street_rules = data.full_street
34
34
 
35
- except ImportError:
35
+ except ImportError as exc:
36
36
  raise e.CountryDetectionMissing(
37
37
  'Detection rules for country "{country}" not found.'.format(
38
38
  country=self.country
39
39
  ),
40
40
  "Error 2",
41
- )
41
+ ) from exc
42
42
 
43
43
  def parse(self, text: str) -> List[address.Address]:
44
44
  """Returns a list of addresses found in text
@@ -100,7 +100,7 @@ class AddressParser:
100
100
  if k not in keys:
101
101
  keys.append(k)
102
102
  vals.append(v)
103
- return dict(zip(keys, vals))
103
+ return dict(zip(keys, vals, strict=True))
104
104
 
105
105
  @staticmethod
106
106
  def _normalize_string(text: str) -> str:
@@ -1,17 +1,17 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  """
4
- pyap.source_US.data
5
- ~~~~~~~~~~~~~~~~~~~~
4
+ pyap.source_US.data
5
+ ~~~~~~~~~~~~~~~~~~~~
6
6
 
7
- This module provides regular expression definitions required for
8
- detecting Canada addresses.
7
+ This module provides regular expression definitions required for
8
+ detecting Canada addresses.
9
9
 
10
- The module is expected to always contain 'full_address' variable containing
11
- all address parsing definitions.
10
+ The module is expected to always contain 'full_address' variable containing
11
+ all address parsing definitions.
12
12
 
13
- :copyright: (c) 2015 by Vladimir Goncharov.
14
- :license: MIT, see LICENSE for more details.
13
+ :copyright: (c) 2015 by Vladimir Goncharov.
14
+ :license: MIT, see LICENSE for more details.
15
15
  """
16
16
 
17
17
  import re
@@ -149,9 +149,7 @@ post_direction = r"""
149
149
  O[\.\ ]
150
150
  )
151
151
  )
152
- """.format(
153
- d="[\ ,]"
154
- )
152
+ """.format(d=r"[\ ,]")
155
153
 
156
154
  # Regexp for matching street type
157
155
  # According to
@@ -308,9 +306,7 @@ street_type = r"""
308
306
  [\(\ \,]{route_symbols}
309
307
  [Rr][Oo][Uu][Tt][Ee]\ [A-Za-z0-9]+[\)\ \,]{route_symbols}
310
308
  )?
311
- """.format(
312
- div="[\.\ ,]{0,2}", route_symbols="{0,3}"
313
- )
309
+ """.format(div=r"[\.\ ,]{0,2}", route_symbols="{0,3}")
314
310
 
315
311
  floor = r"""
316
312
  (?P<floor>
@@ -399,11 +395,11 @@ po_box = r"""
399
395
  """Define detection rules for a second type of address format
400
396
  (the French one)
401
397
  """
402
- street_number_b = re.sub("<([a-z\_]+)>", r"<\1_b>", street_number)
403
- street_name_b = re.sub("<([a-z\_]+)>", r"<\1_b>", street_name)
404
- street_type_b = re.sub("<([a-z\_]+)>", r"<\1_b>", street_type)
405
- po_box_b = re.sub("<([a-z\_]+)>", r"<\1_b>", po_box)
406
- post_direction_b = re.sub("<([a-z\_]+)>", r"<\1_b>", post_direction)
398
+ street_number_b = re.sub(r"<([a-z\_]+)>", r"<\1_b>", street_number)
399
+ street_name_b = re.sub(r"<([a-z\_]+)>", r"<\1_b>", street_name)
400
+ street_type_b = re.sub(r"<([a-z\_]+)>", r"<\1_b>", street_type)
401
+ po_box_b = re.sub(r"<([a-z\_]+)>", r"<\1_b>", po_box)
402
+ post_direction_b = re.sub(r"<([a-z\_]+)>", r"<\1_b>", post_direction)
407
403
 
408
404
  po_box_positive_lookahead = r"""
409
405
  (?=
@@ -479,7 +475,7 @@ full_street = r"""
479
475
  po_box=po_box,
480
476
  po_box_b=po_box_b,
481
477
  po_box_positive_lookahead=po_box_positive_lookahead,
482
- div="[\ ,]{1,2}",
478
+ div=r"[\ ,]{1,2}",
483
479
  )
484
480
 
485
481
  # region1 here is actually a "province"
@@ -551,8 +547,8 @@ country = r"""
551
547
  """
552
548
 
553
549
  # define detection rules for postal code placed in different parts of address
554
- postal_code_b = re.sub("<([a-z\_]+)>", r"<\1_b>", postal_code)
555
- postal_code_c = re.sub("<([a-z\_]+)>", r"<\1_c>", postal_code)
550
+ postal_code_b = re.sub(r"<([a-z\_]+)>", r"<\1_b>", postal_code)
551
+ postal_code_c = re.sub(r"<([a-z\_]+)>", r"<\1_c>", postal_code)
556
552
 
557
553
  full_address = r"""
558
554
  (?P<full_address>
@@ -569,7 +565,7 @@ full_address = r"""
569
565
  )
570
566
  """.format(
571
567
  full_street=full_street,
572
- div="[\, ]{,2}",
568
+ div=r"[\, ]{,2}",
573
569
  city=city,
574
570
  region1=region1,
575
571
  country=country,
@@ -1,20 +1,19 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  """
4
- pyap.source_GB.data
5
- ~~~~~~~~~~~~~~~~~~~~
4
+ pyap.source_GB.data
5
+ ~~~~~~~~~~~~~~~~~~~~
6
6
 
7
- This module provides regular expression definitions required for
8
- detecting British/GB/UK addresses.
7
+ This module provides regular expression definitions required for
8
+ detecting British/GB/UK addresses.
9
9
 
10
- The module is expected to always contain 'full_address' variable containing
11
- all address parsing definitions.
10
+ The module is expected to always contain 'full_address' variable containing
11
+ all address parsing definitions.
12
12
 
13
- :copyright: (c) 2015 by Vladimir Goncharov.
14
- :license: MIT, see LICENSE for more details.
13
+ :copyright: (c) 2015 by Vladimir Goncharov.
14
+ :license: MIT, see LICENSE for more details.
15
15
  """
16
16
 
17
-
18
17
  """Numerals from one to nine
19
18
  Note: here and below we use syntax like '[Oo][Nn][Ee]'
20
19
  instead of '(one)(?i)' to match 'One' or 'oNe' because
@@ -1,17 +1,17 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  """
4
- pyap.source_US.data
5
- ~~~~~~~~~~~~~~~~~~~~
4
+ pyap.source_US.data
5
+ ~~~~~~~~~~~~~~~~~~~~
6
6
 
7
- This module provides regular expression definitions required for
8
- detecting US addresses.
7
+ This module provides regular expression definitions required for
8
+ detecting US addresses.
9
9
 
10
- The module is expected to always contain 'full_address' variable containing
11
- all address parsing definitions.
10
+ The module is expected to always contain 'full_address' variable containing
11
+ all address parsing definitions.
12
12
 
13
- :copyright: (c) 2015 by Vladimir Goncharov.
14
- :license: MIT, see LICENSE for more details.
13
+ :copyright: (c) 2015 by Vladimir Goncharov.
14
+ :license: MIT, see LICENSE for more details.
15
15
  """
16
16
 
17
17
  import string
@@ -259,9 +259,7 @@ post_direction_re = r"""
259
259
 
260
260
  numbered_avenue_re = r"""
261
261
  (?:{post_direction_re}\ [Aa][Vv][Ee](?:\.|[Nn][Uu][Ee])?\ \d{{1,2}})
262
- """.format(
263
- post_direction_re=post_direction_re
264
- )
262
+ """.format(post_direction_re=post_direction_re)
265
263
 
266
264
 
267
265
  single_street_name_list = [
@@ -286,9 +284,7 @@ numbered_state_highway = r"""
286
284
  (?:{states}\ \d{{1,4}}(?!\d))
287
285
  |
288
286
  (?:[Ss][Tt][Aa][Tt][Ee]\s[Hh][Ww][Yy]\s\d{{1,4}}(?!\d))
289
- """.format(
290
- states=state_highway_abbrvs_regex()
291
- )
287
+ """.format(states=state_highway_abbrvs_regex())
292
288
 
293
289
 
294
290
  # Used to handle edge cases where streets don't have a street type:
@@ -334,9 +330,7 @@ post_direction = r"""
334
330
  (?P<post_direction>
335
331
  {post_direction_re}
336
332
  )
337
- """.format(
338
- post_direction_re=post_direction_re
339
- )
333
+ """.format(post_direction_re=post_direction_re)
340
334
 
341
335
  # This list was taken from: https://pe.usps.com/text/pub28/28apc_002.htm
342
336
  # Bay, Broadway and Lp (abbreviation for Loop) were added to the list
@@ -358,7 +352,7 @@ street_type_list = [
358
352
  "Avenue",
359
353
  "Avn",
360
354
  "Avnue",
361
- "Bay(?!\ [1-9])",
355
+ r"Bay(?!\ [1-9])",
362
356
  "Bayoo",
363
357
  "Bayou",
364
358
  "Bch",
@@ -573,6 +567,7 @@ street_type_list = [
573
567
  "Hbr",
574
568
  "Hbrs",
575
569
  "Heights",
570
+ "Hgts",
576
571
  "Highway",
577
572
  "Highwy",
578
573
  "Hill",
@@ -906,12 +901,12 @@ street_type_list = [
906
901
 
907
902
  street_type_leading_list = [
908
903
  "Camino",
909
- "El\ Camino",
904
+ r"El\ Camino",
910
905
  "Via",
911
906
  "Avenue",
912
907
  "Blvd",
913
908
  "Ave",
914
- "La\ Rue",
909
+ r"La\ Rue",
915
910
  "Rue",
916
911
  ]
917
912
 
@@ -1082,9 +1077,7 @@ floor = r"""
1082
1077
  {floor_indic}\ ?\#?\d+[A-Za-z]{{0,2}}
1083
1078
  )
1084
1079
  )
1085
- """.format(
1086
- floor_indic=floor_indic
1087
- )
1080
+ """.format(floor_indic=floor_indic)
1088
1081
 
1089
1082
  tower = r"(?:{re_post_direction}\ [Tt][Oo][Ww][Ee][Rr])".format(
1090
1083
  re_post_direction=post_direction_re
@@ -1131,10 +1124,19 @@ building = r"""
1131
1124
  # A unit id is short and always contains a digit.
1132
1125
  # A plain word like the "Shore" in "Bay Shore" is a city, not
1133
1126
  # a unit id - we don't let one start with three letters.
1134
- occupancy_details = (
1135
- r"(?:(?:\#\ )?(?![A-Za-z]{{3}})[A-Za-z\#\&\-\d]{{1,7}}"
1136
- r"(?:\s?{post_direction_re})?)".format(post_direction_re=post_direction_re)
1137
- )
1127
+ # A unit id can also come in two parts, a letter and a number: "STE C 199".
1128
+ occupancy_details = r"""
1129
+ (?:
1130
+ # two-part unit id: a letter and a number, e.g. "C 199"
1131
+ [A-Za-z]\ \d{{1,5}}\b
1132
+ |
1133
+ # single unit id, e.g. "4B", "#12", "A-3"
1134
+ (?:\#\ )?
1135
+ (?![A-Za-z]{{3}})
1136
+ [A-Za-z\#\&\-\d]{{1,7}}
1137
+ (?:\s?{post_direction_re})?
1138
+ )
1139
+ """.format(post_direction_re=post_direction_re)
1138
1140
  occupancy = r"""
1139
1141
  (?P<occupancy>
1140
1142
  (?:
@@ -1203,9 +1205,7 @@ occupancy = r"""
1203
1205
  )
1204
1206
  )
1205
1207
  )
1206
- """.format(
1207
- occupancy_details=occupancy_details
1208
- )
1208
+ """.format(occupancy_details=occupancy_details)
1209
1209
 
1210
1210
  mail_stop = r"""
1211
1211
  (?P<mail_stop>
@@ -1238,9 +1238,7 @@ po_box = r"""
1238
1238
  |
1239
1239
  (?:[Dd][Rr][Aa][Ww][Ee][Rr]\ +[A-Z]\b)
1240
1240
  )
1241
- """.format(
1242
- po_marker=po_marker
1243
- )
1241
+ """.format(po_marker=po_marker)
1244
1242
 
1245
1243
  phone_number = r"""
1246
1244
  (?:
@@ -1383,9 +1381,7 @@ def make_region1(idx: Optional[str] = None):
1383
1381
  {state_abbrvs}
1384
1382
  )
1385
1383
  )
1386
- """.format(
1387
- state_abbrvs=states_abbrvs_regex(), maybe_idx=maybe_idx
1388
- )
1384
+ """.format(state_abbrvs=states_abbrvs_regex(), maybe_idx=maybe_idx)
1389
1385
 
1390
1386
 
1391
1387
  # TODO: doesn't catch cities containing French characters
@@ -1427,7 +1423,7 @@ def make_region1_postal_code(
1427
1423
  def _indexed_region1(idx: Optional[str] = None):
1428
1424
  return rf"""(?:{part_div} {make_region1(idx)})"""
1429
1425
 
1430
- _postal_code = f"""(?:{part_div}|\-)? {postal_code}"""
1426
+ _postal_code = rf"""(?:{part_div}|\-)? {postal_code}"""
1431
1427
  return rf"""
1432
1428
  (?:{_indexed_region1("a")}?(?:{part_div}{make_country("b")})?{_postal_code}{_indexed_region1("b")}?
1433
1429
  |{_indexed_region1("c")}(?![-,.\sA-Za-z]{{0,10}}{postal_code_re}))
@@ -1,13 +1,13 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  """
4
- pyap.utils
5
- ~~~~~~~~~~~~~~~~
4
+ pyap.utils
5
+ ~~~~~~~~~~~~~~~~
6
6
 
7
- This module provides some utility functions.
7
+ This module provides some utility functions.
8
8
 
9
- :copyright: (c) 2015 by Vladimir Goncharov.
10
- :license: MIT, see LICENSE for more details.
9
+ :copyright: (c) 2015 by Vladimir Goncharov.
10
+ :license: MIT, see LICENSE for more details.
11
11
  """
12
12
 
13
13
  import re