fr-phonenumbers 0.1.0__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.
@@ -0,0 +1,13 @@
1
+ # Python-generated files
2
+ __pycache__/
3
+ *.py[oc]
4
+ build/
5
+ dist/
6
+ wheels/
7
+ *.egg-info
8
+
9
+ # Virtual environments
10
+ .venv
11
+
12
+ # Internal notes/scripts/...
13
+ hidden/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 RIENK Consulting
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,56 @@
1
+ Metadata-Version: 2.5
2
+ Name: fr-phonenumbers
3
+ Version: 0.1.0
4
+ Summary: Détecteur d'opérateur pour les numéros de téléphone français.
5
+ Project-URL: Homepage, https://github.com/RIENK-Consulting/fr-phonenumbers
6
+ Author-email: RIENK Consulting <contact@rienkconsulting.fr>
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Topic :: Communications :: Telephony
13
+ Requires-Python: >=3.10
14
+ Description-Content-Type: text/markdown
15
+
16
+ ![Tests](https://github.com/RIENK-Consulting/fr-phonenumbers/actions/workflows/test.yml/badge.svg)
17
+ ![Python Version](https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13-blue)
18
+ [![PyPI version](https://img.shields.io/pypi/v/fr-phonenumbers.svg)](https://pypi.org/project/fr-phonenumbers/)
19
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
20
+
21
+ # fr-phonenumbers
22
+
23
+ Bibliothèque Python ultra-légère et sans dépendance externe pour identifier l'opérateur et la zone des numéros de téléphone français.
24
+
25
+ ## Le Parti Pris
26
+
27
+ Contrairement aux bibliothèques lourdes et complexes, **fr-phonenumbers** fait le choix de la simplicité et de la robustesse :
28
+ * **Zero dépendance :** Utilise exclusivement la bibliothèque standard de Python.
29
+ * **100% Autonome (Offline-friendly) :** Les données sont embarquées directement dans le paquet. Aucun téléchargement réseau à l'exécution, ce qui garantit un fonctionnement parfait derrière les proxys d'entreprise.
30
+ * **Performance ($O(\log N)$) :** La recherche s'appuie sur le module natif `bisect` appliqué à des plages de numéros triées, offrant des performances instantanées.
31
+
32
+ ## Installation
33
+
34
+ ```bash
35
+ pip install fr-phonenumbers
36
+ ```
37
+
38
+ ## Utilisation rapide
39
+
40
+ ```python
41
+ from fr_phonenumbers import get_operator
42
+
43
+ resultat = get_operator("0105712345")
44
+ print(resultat)
45
+ # Sortie : {'code': 'FRTE', 'operator': '...', 'zone': 'Métropole'}
46
+ ```
47
+
48
+ ## Sources des Données
49
+
50
+ Les données de numérotation sont issues des publications officielles de l'ARCEP sur data.gouv.fr :
51
+ * [Ressources en numérotation téléphonique](https://www.data.gouv.fr/datasets/ressources-en-numerotation-telephonique)
52
+ * [Identifiants de communications électroniques](https://www.data.gouv.fr/datasets/identifiants-de-communications-electroniques)
53
+
54
+ ## Licence
55
+
56
+ Distribué sous licence MIT. Voir le fichier `LICENSE` pour plus de détails.
@@ -0,0 +1,41 @@
1
+ ![Tests](https://github.com/RIENK-Consulting/fr-phonenumbers/actions/workflows/test.yml/badge.svg)
2
+ ![Python Version](https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13-blue)
3
+ [![PyPI version](https://img.shields.io/pypi/v/fr-phonenumbers.svg)](https://pypi.org/project/fr-phonenumbers/)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+
6
+ # fr-phonenumbers
7
+
8
+ Bibliothèque Python ultra-légère et sans dépendance externe pour identifier l'opérateur et la zone des numéros de téléphone français.
9
+
10
+ ## Le Parti Pris
11
+
12
+ Contrairement aux bibliothèques lourdes et complexes, **fr-phonenumbers** fait le choix de la simplicité et de la robustesse :
13
+ * **Zero dépendance :** Utilise exclusivement la bibliothèque standard de Python.
14
+ * **100% Autonome (Offline-friendly) :** Les données sont embarquées directement dans le paquet. Aucun téléchargement réseau à l'exécution, ce qui garantit un fonctionnement parfait derrière les proxys d'entreprise.
15
+ * **Performance ($O(\log N)$) :** La recherche s'appuie sur le module natif `bisect` appliqué à des plages de numéros triées, offrant des performances instantanées.
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ pip install fr-phonenumbers
21
+ ```
22
+
23
+ ## Utilisation rapide
24
+
25
+ ```python
26
+ from fr_phonenumbers import get_operator
27
+
28
+ resultat = get_operator("0105712345")
29
+ print(resultat)
30
+ # Sortie : {'code': 'FRTE', 'operator': '...', 'zone': 'Métropole'}
31
+ ```
32
+
33
+ ## Sources des Données
34
+
35
+ Les données de numérotation sont issues des publications officielles de l'ARCEP sur data.gouv.fr :
36
+ * [Ressources en numérotation téléphonique](https://www.data.gouv.fr/datasets/ressources-en-numerotation-telephonique)
37
+ * [Identifiants de communications électroniques](https://www.data.gouv.fr/datasets/identifiants-de-communications-electroniques)
38
+
39
+ ## Licence
40
+
41
+ Distribué sous licence MIT. Voir le fichier `LICENSE` pour plus de détails.
@@ -0,0 +1,36 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "fr-phonenumbers"
7
+ version = "0.1.0"
8
+ description = "Détecteur d'opérateur pour les numéros de téléphone français."
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "MIT"
12
+ authors = [
13
+ { name = "RIENK Consulting", email = "contact@rienkconsulting.fr" }
14
+ ]
15
+ classifiers = [
16
+ "Programming Language :: Python :: 3",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Operating System :: OS Independent",
19
+ "Topic :: Communications :: Telephony",
20
+ ]
21
+ dependencies = []
22
+
23
+ [project.urls]
24
+ Homepage = "https://github.com/RIENK-Consulting/fr-phonenumbers"
25
+
26
+ [tool.hatch.build.targets.sdist]
27
+ include = [
28
+ "/src/fr_phonenumbers",
29
+ "README.md",
30
+ "LICENSE",
31
+ ]
32
+
33
+ [dependency-groups]
34
+ dev = [
35
+ "pytest>=9.1.1",
36
+ ]
@@ -0,0 +1,92 @@
1
+ import csv
2
+ import bisect
3
+ import importlib.resources
4
+ from typing import Optional, Dict, Tuple, List
5
+ from . import data
6
+
7
+ _OPERATORS_CACHE: Optional[Dict[str, str]] = None
8
+ _RANGES_CACHE: Optional[List[Tuple[int, int, str, str]]] = None
9
+
10
+
11
+ def _load_data() -> Tuple[Dict[str, str], List[Tuple[int, int, str, str]]]:
12
+ """Charge et met en cache les fichiers CSV au premier appel."""
13
+ global _OPERATORS_CACHE, _RANGES_CACHE
14
+ if _OPERATORS_CACHE is not None and _RANGES_CACHE is not None:
15
+ return _OPERATORS_CACHE, _RANGES_CACHE
16
+
17
+ operators = {}
18
+ with importlib.resources.files(data).joinpath("operators.csv").open("r", encoding="utf-8") as f:
19
+ reader = csv.DictReader(f)
20
+ for row in reader:
21
+ operators[row["code"].strip()] = row["operateur"].strip()
22
+
23
+ ranges = []
24
+ with importlib.resources.files(data).joinpath("num_ranges.csv").open("r", encoding="utf-8") as f:
25
+ reader = csv.DictReader(f)
26
+ for row in reader:
27
+ start = int(row["num_debut"])
28
+ end = int(row["num_fin"])
29
+ op_code = row["operateur"].strip()
30
+ zone = row["zone"].strip()
31
+ ranges.append((start, end, op_code, zone))
32
+
33
+ ranges.sort(key=lambda x: x[0])
34
+
35
+ _OPERATORS_CACHE = operators
36
+ _RANGES_CACHE = ranges
37
+ return _OPERATORS_CACHE, _RANGES_CACHE
38
+
39
+
40
+ def parse_phone_number(numero_str: str) -> int:
41
+ """
42
+ Nettoie, valide un numéro de téléphone français et retourne sa version entière (ex: 105700000).
43
+ Lève une ValueError si le format est invalide.
44
+ """
45
+ if not isinstance(numero_str, str):
46
+ raise ValueError("Le numéro doit être une chaîne de caractères.")
47
+
48
+ cleaned = "".join(c for c in numero_str if c.isdigit() or c == "+")
49
+
50
+ if cleaned.startswith("+33"):
51
+ cleaned = "0" + cleaned[3:]
52
+ elif cleaned.startswith("0033"):
53
+ cleaned = "0" + cleaned[4:]
54
+
55
+ if not cleaned.startswith("0") or len(cleaned) != 10:
56
+ raise ValueError(f"Format de numéro français invalide : '{numero_str}'")
57
+
58
+ try:
59
+ return int(cleaned)
60
+ except ValueError:
61
+ raise ValueError(f"Impossible de convertir le numéro en entier : '{numero_str}'")
62
+
63
+
64
+ def get_operator(numero_str: str) -> Optional[Dict[str, str]]:
65
+ """
66
+ Prend un numéro français (string) et retourne un dictionnaire avec les infos de l'opérateur,
67
+ ou None si le numéro n'est rattaché à aucune plage connue.
68
+ """
69
+ operators, ranges = _load_data()
70
+
71
+ try:
72
+ num_int = parse_phone_number(numero_str)
73
+ except ValueError:
74
+ return None
75
+
76
+ bornes_min = [r[0] for r in ranges]
77
+ idx = bisect.bisect_right(bornes_min, num_int) - 1
78
+
79
+ if idx < 0:
80
+ return None
81
+
82
+ borne_min, borne_max, op_code, zone = ranges[idx]
83
+
84
+ if borne_min <= num_int <= borne_max:
85
+ operator_name = operators.get(op_code, op_code)
86
+ return {
87
+ "code": op_code,
88
+ "operator": operator_name,
89
+ "zone": zone,
90
+ }
91
+
92
+ return None