pystandards 0.0.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.
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2026 The Python Packaging Authority
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
@@ -0,0 +1,54 @@
1
+ Metadata-Version: 2.4
2
+ Name: pystandards
3
+ Version: 0.0.1
4
+ Summary: Standards but in Python
5
+ License-File: LICENSE
6
+ Author: danialcala94
7
+ Author-email: danielalcalavalera@gmail.com
8
+ Requires-Python: >=3.8,<3.14
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.8
11
+ Classifier: Programming Language :: Python :: 3.9
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Requires-Dist: exrex (>=0.0.1,<9999.0.0)
17
+ Requires-Dist: yta_validation (>=0.0.1,<1.0.0)
18
+ Description-Content-Type: text/markdown
19
+
20
+ # pystandards - Standards but in Python
21
+
22
+ > Typed standards, constants, enums and canonical values for Python.
23
+
24
+ `pystandards` provides strongly-typed constants and standardized values for common domains such as HTTP, MIME types, file extensions, languages, encodings, and more.
25
+
26
+ Designed for:
27
+
28
+ - Clean APIs
29
+ - Type safety
30
+ - IDE autocompletion
31
+ - Validation
32
+ - Better developer experience
33
+
34
+ ---
35
+
36
+ # Features
37
+
38
+ - Typed enums based on a custom `BaseEnum`
39
+ - Safe conversion from raw values
40
+ - Canonical standards and constants
41
+ - Consistent API across domains
42
+ - Lightweight and dependency-free
43
+ - Fully type-hinted
44
+
45
+ ---
46
+
47
+ # Installation
48
+
49
+ ```bash
50
+ pip install pystandards
51
+ ```
52
+ ---
53
+
54
+ 💪 Build fast, believe in yourself and keep going. Never stop!
@@ -0,0 +1,35 @@
1
+ # pystandards - Standards but in Python
2
+
3
+ > Typed standards, constants, enums and canonical values for Python.
4
+
5
+ `pystandards` provides strongly-typed constants and standardized values for common domains such as HTTP, MIME types, file extensions, languages, encodings, and more.
6
+
7
+ Designed for:
8
+
9
+ - Clean APIs
10
+ - Type safety
11
+ - IDE autocompletion
12
+ - Validation
13
+ - Better developer experience
14
+
15
+ ---
16
+
17
+ # Features
18
+
19
+ - Typed enums based on a custom `BaseEnum`
20
+ - Safe conversion from raw values
21
+ - Canonical standards and constants
22
+ - Consistent API across domains
23
+ - Lightweight and dependency-free
24
+ - Fully type-hinted
25
+
26
+ ---
27
+
28
+ # Installation
29
+
30
+ ```bash
31
+ pip install pystandards
32
+ ```
33
+ ---
34
+
35
+ 💪 Build fast, believe in yourself and keep going. Never stop!
@@ -0,0 +1,31 @@
1
+ [project]
2
+ name = "pystandards"
3
+ version = "0.0.1"
4
+ description = "Standards but in Python"
5
+ authors = [
6
+ {name = "danialcala94",email = "danielalcalavalera@gmail.com"}
7
+ ]
8
+ readme = "README.md"
9
+ requires-python = ">=3.8,<3.14"
10
+
11
+ [tool.poetry.dependencies]
12
+ # Mandatory
13
+ yta_validation = { version = ">=0.0.1,<1.0.0", optional = false }
14
+ exrex = { version = ">=0.0.1,<9999.0.0", optional = false }
15
+ # Optional
16
+
17
+ [tool.poetry]
18
+ packages = [{include = "pystandards", from = "src"}]
19
+
20
+ [tool.poetry.group.dev.dependencies]
21
+ pytest = "^8.3.5"
22
+
23
+ [tool.pytest.ini_options]
24
+ markers = [
25
+ "mandatory: mandatory tests for release",
26
+ "additional: exhaustive and demanding tests"
27
+ ]
28
+
29
+ [build-system]
30
+ requires = ["poetry-core>=2.0.0,<3.0.0"]
31
+ build-backend = "poetry.core.masonry.api"
File without changes
@@ -0,0 +1,100 @@
1
+ from enum import Enum
2
+ from typing import Union
3
+
4
+
5
+ class BaseEnum(Enum):
6
+ """
7
+ Custom Enum class that is able to autodetect
8
+ and parse values based on its `name` and/or
9
+ its `value`.
10
+ """
11
+
12
+ @classmethod
13
+ def names(
14
+ cls
15
+ ) -> list[str]:
16
+ """
17
+ A list containing all the names that are registered
18
+ in this `BaseEnum` class.
19
+ """
20
+ return [
21
+ x.name
22
+ for x in cls
23
+ ]
24
+
25
+ @classmethod
26
+ def values(
27
+ cls
28
+ ) -> list[any]:
29
+ """
30
+ A list containing all the values that are registered
31
+ in this `BaseEnum` class.
32
+ """
33
+ return [
34
+ x.value
35
+ for x in cls
36
+ ]
37
+
38
+ @classmethod
39
+ def _normalized_map(
40
+ cls
41
+ ):
42
+ """
43
+ *For internal use only*
44
+
45
+ Internal cache to make it faster when the list
46
+ of items is big.
47
+ """
48
+
49
+ if not hasattr(cls, '__normalized_map'):
50
+ mapping = {}
51
+
52
+ for item in cls:
53
+ mapping[item.name.lower()] = item
54
+ mapping[str(item.value).strip().lower()] = item
55
+ cls.__normalized_map = mapping
56
+
57
+ return cls.__normalized_map
58
+
59
+ @classmethod
60
+ def to_enum(
61
+ cls,
62
+ value: any
63
+ ):
64
+ """
65
+ Convert a raw value into a valid enum member,
66
+ raising an exception if there is no item with
67
+ that `value` or as name or value.
68
+
69
+ Comparison is case-insensitive and checks:
70
+ - enum.value
71
+ - enum.name
72
+ """
73
+ if isinstance(value, cls):
74
+ return value
75
+
76
+ normalized = str(value).strip().lower()
77
+
78
+ try:
79
+ return cls._normalized_map()[normalized]
80
+
81
+ except KeyError:
82
+ raise ValueError(
83
+ f'{value!r} is not a valid {cls.__name__}'
84
+ ) from None
85
+
86
+ @classmethod
87
+ def try_to_enum(
88
+ cls,
89
+ value: any,
90
+ default: Union[any, None] = None
91
+ ):
92
+ """
93
+ Try to parse the `value` provided as the Enum,
94
+ returning the `default` if not possible because
95
+ there is no `Enum` item with that value.
96
+ """
97
+ try:
98
+ return BaseEnum.to_enum(value)
99
+ except:
100
+ return default
@@ -0,0 +1,132 @@
1
+ from pystandards.enum import BaseEnum as Enum
2
+
3
+
4
+ class HttpContentType(Enum):
5
+ """
6
+ The `content_type` field that could come in the
7
+ response of a http request we make.
8
+ """
9
+
10
+ # JSON
11
+ APPLICATION_JSON = 'application/json'
12
+ APPLICATION_LD_JSON = 'application/ld+json'
13
+ APPLICATION_PROBLEM_JSON = 'application/problem+json'
14
+
15
+ # Text
16
+ TEXT_PLAIN = 'text/plain'
17
+ TEXT_HTML = 'text/html'
18
+ TEXT_CSS = 'text/css'
19
+ TEXT_CSV = 'text/csv'
20
+ TEXT_XML = 'text/xml'
21
+ TEXT_EVENT_STREAM = 'text/event-stream'
22
+ TEXT_JAVASCRIPT = 'text/javascript'
23
+
24
+ # XML / Markup
25
+ APPLICATION_XML = 'application/xml'
26
+ APPLICATION_XHTML_XML = 'application/xhtml+xml'
27
+
28
+ # JavaScript
29
+ APPLICATION_JAVASCRIPT = 'application/javascript'
30
+
31
+ # Binary / Generic files
32
+ APPLICATION_OCTET_STREAM = 'application/octet-stream'
33
+ APPLICATION_PDF = 'application/pdf'
34
+ APPLICATION_ZIP = 'application/zip'
35
+ APPLICATION_GZIP = 'application/gzip'
36
+ APPLICATION_X_TAR = 'application/x-tar'
37
+
38
+ # Forms
39
+ MULTIPART_FORM_DATA = 'multipart/form-data'
40
+ APPLICATION_X_WWW_FORM_URLENCODED = (
41
+ 'application/x-www-form-urlencoded'
42
+ )
43
+
44
+ # Streaming
45
+ APPLICATION_NDJSON = 'application/x-ndjson'
46
+
47
+ # SQL
48
+ APPLICATION_SQL = 'application/sql'
49
+
50
+ # Images
51
+ IMAGE_JPEG = 'image/jpeg'
52
+ IMAGE_PNG = 'image/png'
53
+ IMAGE_WEBP = 'image/webp'
54
+ IMAGE_GIF = 'image/gif'
55
+ IMAGE_SVG_XML = 'image/svg+xml'
56
+ IMAGE_BMP = 'image/bmp'
57
+ IMAGE_X_ICON = 'image/x-icon'
58
+
59
+ # Video
60
+ VIDEO_MP4 = 'video/mp4'
61
+ VIDEO_WEBM = 'video/webm'
62
+ VIDEO_QUICKTIME = 'video/quicktime'
63
+ VIDEO_X_MSVIDEO = 'video/x-msvideo'
64
+
65
+ # Audio
66
+ AUDIO_WAV = 'audio/wav'
67
+ AUDIO_MPEG = 'audio/mpeg'
68
+ AUDIO_OGG = 'audio/ogg'
69
+ AUDIO_WEBM = 'audio/webm'
70
+ AUDIO_FLAC = 'audio/flac'
71
+
72
+ # Fonts
73
+ FONT_WOFF = 'font/woff'
74
+ FONT_WOFF2 = 'font/woff2'
75
+
76
+
77
+ class HttpMethod(Enum):
78
+ """
79
+ The methods that are supported in the Http
80
+ requests que make.
81
+ """
82
+
83
+ # Standard methods
84
+ GET = 'GET'
85
+ POST = 'POST'
86
+ PUT = 'PUT'
87
+ DELETE = 'DELETE'
88
+ PATCH = 'PATCH'
89
+ HEAD = 'HEAD'
90
+ OPTIONS = 'OPTIONS'
91
+ TRACE = 'TRACE'
92
+ CONNECT = 'CONNECT'
93
+
94
+ # WebDAV methods
95
+ PROPFIND = 'PROPFIND'
96
+ PROPPATCH = 'PROPPATCH'
97
+ MKCOL = 'MKCOL'
98
+ COPY = 'COPY'
99
+ MOVE = 'MOVE'
100
+ LOCK = 'LOCK'
101
+ UNLOCK = 'UNLOCK'
102
+
103
+ # Versioning / Delta encoding
104
+ VERSION_CONTROL = 'VERSION-CONTROL'
105
+ REPORT = 'REPORT'
106
+ CHECKOUT = 'CHECKOUT'
107
+ CHECKIN = 'CHECKIN'
108
+ UNCHECKOUT = 'UNCHECKOUT'
109
+ MKWORKSPACE = 'MKWORKSPACE'
110
+ UPDATE = 'UPDATE'
111
+ LABEL = 'LABEL'
112
+ MERGE = 'MERGE'
113
+ BASELINE_CONTROL = 'BASELINE-CONTROL'
114
+ MKACTIVITY = 'MKACTIVITY'
115
+
116
+ # UPnP
117
+ NOTIFY = 'NOTIFY'
118
+ SUBSCRIBE = 'SUBSCRIBE'
119
+ UNSUBSCRIBE = 'UNSUBSCRIBE'
120
+
121
+ # RFC 5789
122
+ SEARCH = 'SEARCH'
123
+
124
+ # CalDAV
125
+ MKCALENDAR = 'MKCALENDAR'
126
+
127
+ # RFC 2068
128
+ LINK = 'LINK'
129
+ UNLINK = 'UNLINK'
130
+
131
+ # Icecast / unofficial
132
+ SOURCE = 'SOURCE'