detrack 0.1.0__py3-none-any.whl

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.
detrack/__init__.py ADDED
@@ -0,0 +1,4 @@
1
+ from detrack.core import clean, clean_query, DetrackResult
2
+ from detrack.patterns import DEFAULT_PATTERNS
3
+
4
+ __all__ = ["clean", "clean_query", "DEFAULT_PATTERNS", "DetrackResult"]
detrack/core.py ADDED
@@ -0,0 +1,69 @@
1
+ from dataclasses import dataclass
2
+ from urllib.parse import parse_qsl, urlencode, urlsplit, urlunsplit
3
+ from urllib.parse import SplitResult
4
+
5
+ from detrack.patterns import DEFAULT_PATTERNS
6
+
7
+
8
+ @dataclass
9
+ class DetrackResult:
10
+ url: str
11
+ parsed_url: SplitResult
12
+ cleaned_params: dict[str, str]
13
+ removed_params: list[str]
14
+
15
+
16
+ def _filter_pairs(
17
+ query: str,
18
+ patterns: list[str] | None = None,
19
+ ) -> tuple[list[tuple[str, str]], list[str]]:
20
+ patterns_set = frozenset(p.lower() for p in (patterns or list(DEFAULT_PATTERNS)))
21
+ pairs = parse_qsl(query, keep_blank_values=True)
22
+ cleaned: list[tuple[str, str]] = []
23
+ removed: list[str] = []
24
+ for key, val in pairs:
25
+ if key.lower() in patterns_set:
26
+ removed.append(key)
27
+ else:
28
+ cleaned.append((key, val))
29
+ return cleaned, removed
30
+
31
+
32
+ def clean_query(query: str, patterns: list[str] | None = None) -> str:
33
+ cleaned, _ = _filter_pairs(query, patterns)
34
+ return urlencode(cleaned, doseq=True)
35
+
36
+
37
+ def clean(url: str, patterns: list[str] | None = None) -> DetrackResult:
38
+ try:
39
+ parsed = urlsplit(url)
40
+ if not parsed.query:
41
+ return DetrackResult(
42
+ url=url,
43
+ parsed_url=parsed,
44
+ cleaned_params={},
45
+ removed_params=[],
46
+ )
47
+ cleaned_pairs, removed = _filter_pairs(parsed.query, patterns)
48
+ cleaned_qs = urlencode(cleaned_pairs, doseq=True)
49
+ cleaned_dict = dict(cleaned_pairs)
50
+ new_url = urlunsplit((
51
+ parsed.scheme,
52
+ parsed.netloc,
53
+ parsed.path,
54
+ cleaned_qs,
55
+ parsed.fragment,
56
+ ))
57
+ return DetrackResult(
58
+ url=new_url,
59
+ parsed_url=parsed,
60
+ cleaned_params=cleaned_dict,
61
+ removed_params=removed,
62
+ )
63
+ except Exception:
64
+ return DetrackResult(
65
+ url=url,
66
+ parsed_url=urlsplit(""),
67
+ cleaned_params={},
68
+ removed_params=[],
69
+ )
detrack/patterns.py ADDED
@@ -0,0 +1,24 @@
1
+ DEFAULT_PATTERNS = frozenset({
2
+ # UTM
3
+ "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content",
4
+ "utm_id", "utm_cid", "utm_reader", "utm_viz", "utm_pubreferrer",
5
+ "utm_nooverride",
6
+ # Social
7
+ "fbclid", "ref", "source", "si", "sns", "social", "origin",
8
+ # Marketing / Ad
9
+ "gclid", "gclsrc", "dclid", "msclkid", "wbraid", "gbraid",
10
+ "mc_cid", "mc_eid", "trk", "vero_conv", "vero_id",
11
+ "email", "recipient", "campaign_id", "newsletter", "mbid",
12
+ # Analytics
13
+ "_ga", "_gl", "_ke", "_hsenc",
14
+ # Cache busters
15
+ "_", "cb", "cache", "nocache", "rand", "random", "r", "ts", "_t",
16
+ "timestamp",
17
+ # Session / visit
18
+ "session_id", "sid", "phpsessid", "jsessionid", "view_id", "visit_id",
19
+ # Redirect
20
+ "redirect_to", "return_to", "next", "continue",
21
+ # Misc / platform-specific
22
+ "yclid", "igshid", "_openstat", "oft_id", "wt_mc", "mtm_source",
23
+ "mtm_medium", "mtm_campaign", "mtm_keyword", "mtm_content",
24
+ })
@@ -0,0 +1,27 @@
1
+ Metadata-Version: 2.4
2
+ Name: detrack
3
+ Version: 0.1.0
4
+ Summary: Strip tracking parameters from URLs. Deterministically. Zero dependencies.
5
+ Author-email: Emiliano Gandini Outeda <emiliano.gandini@protonmail.com>
6
+ License: MIT
7
+ Project-URL: Source, https://github.com/emiliano-gandini-outeda/detrack
8
+ Keywords: seo,tracking,privacy,utm,url-cleaner
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3 :: Only
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Topic :: Internet :: WWW/HTTP
18
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
+ Requires-Python: >=3.9
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Provides-Extra: test
23
+ Requires-Dist: pytest; extra == "test"
24
+ Dynamic: license-file
25
+
26
+ # detrack
27
+ Strip tracking parameters from URLs. Deterministically. Zero dependencies.
@@ -0,0 +1,8 @@
1
+ detrack/__init__.py,sha256=W-OUl2Oxqa6oyRbPGeYGi2ana3jlCFE3TPeeqhk3_pM,178
2
+ detrack/core.py,sha256=L_0dXYWMHCBa1f8kueyecfbA_gfQwaz8zRXz5jNXAsg,2021
3
+ detrack/patterns.py,sha256=iYK9b-guvJUSdzZYJCyV8czjPlJioTWQ8tS3Jxz-Lvw,975
4
+ detrack-0.1.0.dist-info/licenses/LICENSE,sha256=j-nWtNMq208SfNLoV0UlmFXK9AH3GPZBmZPS5EzZsY4,1080
5
+ detrack-0.1.0.dist-info/METADATA,sha256=o6qJ_b1VxmBL_eSsyGRer-_sRIIu4MDq4jla-HlGxe4,1102
6
+ detrack-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
7
+ detrack-0.1.0.dist-info/top_level.txt,sha256=OsYCxrfpA1LozJyqYvPwAFJJOZMOJXMFtB8G5qXWnpQ,8
8
+ detrack-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Emiliano Gandini Outeda
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 @@
1
+ detrack