cfi-decoder 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.
cfi_decoder/_decode.py ADDED
@@ -0,0 +1,57 @@
1
+ """Core decode function for ISO 10962 CFI codes."""
2
+
3
+ from ._data import ATTRIBUTES, CATEGORIES, GROUPS
4
+
5
+
6
+ def decode(cfi_code: str) -> str:
7
+ """Decode an ISO 10962 CFI code into human-readable descriptions.
8
+
9
+ Args:
10
+ cfi_code: A 6-character CFI code string.
11
+
12
+ Returns:
13
+ Pipe-separated description string, e.g.
14
+ ``"Equities | Shares (Common/Ordinary) | Voting | ..."``.
15
+
16
+ Raises:
17
+ TypeError: If *cfi_code* is not a string.
18
+ ValueError: If the code length is not 6 or any character is unrecognised.
19
+ """
20
+ if not isinstance(cfi_code, str):
21
+ raise TypeError(f"Expected str, got {type(cfi_code).__name__}")
22
+
23
+ code = cfi_code.upper()
24
+
25
+ if len(code) != 6:
26
+ raise ValueError(f"CFI code must be exactly 6 characters, got {len(code)}")
27
+
28
+ cat_char = code[0]
29
+ grp_char = code[1]
30
+
31
+ category = CATEGORIES.get(cat_char)
32
+ if category is None:
33
+ raise ValueError(f"Unknown category: {cat_char!r}")
34
+
35
+ group_map = GROUPS.get(cat_char)
36
+ if group_map is None or grp_char not in group_map:
37
+ raise ValueError(f"Unknown group {grp_char!r} for category {cat_char!r}")
38
+ group = group_map[grp_char]
39
+
40
+ attr_defs = ATTRIBUTES.get((cat_char, grp_char))
41
+ if attr_defs is None:
42
+ raise ValueError(
43
+ f"No attribute definitions for category {cat_char!r}, group {grp_char!r}"
44
+ )
45
+
46
+ parts: list[str] = [category, group]
47
+ for i, (label, values) in enumerate(attr_defs):
48
+ char = code[i + 2]
49
+ desc = values.get(char)
50
+ if desc is None:
51
+ raise ValueError(
52
+ f"Unknown attribute {char!r} at position {i + 3} "
53
+ f"({label}) for category {cat_char!r}, group {grp_char!r}"
54
+ )
55
+ parts.append(desc)
56
+
57
+ return " | ".join(parts)
cfi_decoder/py.typed ADDED
File without changes
@@ -0,0 +1,58 @@
1
+ Metadata-Version: 2.4
2
+ Name: cfi-decoder
3
+ Version: 0.1.0
4
+ Summary: Offline decoder for ISO 10962 CFI (Classification of Financial Instruments) codes
5
+ Keywords: cfi,decoder,iso-10962,finance,classification,financial-instruments
6
+ Author: Arian Šajina
7
+ License-Expression: Apache-2.0
8
+ License-File: LICENSE
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Financial and Insurance Industry
11
+ Classifier: License :: OSI Approved :: GNU Affero General Public License v3
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Topic :: Office/Business :: Financial
19
+ Classifier: Typing :: Typed
20
+ Requires-Python: >=3.10
21
+ Project-URL: Homepage, https://github.com/ariansajina/cfi-decoder
22
+ Project-URL: Issues, https://github.com/ariansajina/cfi-decoder/issues
23
+ Description-Content-Type: text/markdown
24
+
25
+ # cfi-decoder
26
+
27
+ Offline decoder for ISO 10962 CFI (Classification of Financial Instruments) codes.
28
+
29
+ ## How It Works
30
+
31
+ The decoder takes a 6-character CFI code and maps each position to human-readable descriptions:
32
+
33
+ - **Position 1:** Financial instrument category (e.g., `E` = Equities, `D` = Debt)
34
+ - **Position 2:** Subcategory/group within that category (e.g., `S` = Shares for Equities)
35
+ - **Positions 3-6:** Specific attributes based on the category-group combination
36
+
37
+ The `decode()` function returns a pipe-separated string of descriptions for each position.
38
+
39
+ ### Example
40
+
41
+ ```python
42
+ from cfi_decoder import decode
43
+
44
+ result = decode("ESVUFR")
45
+ # Output: "Equities | Shares (Common/Ordinary) | Voting | Free | Fully Paid | Registered"
46
+ ```
47
+
48
+ ### Implementation
49
+
50
+ The decoder is implemented as a series of dictionary lookups against lookup tables defined in [`src/cfi_decoder/_data.py`](src/cfi_decoder/_data.py). The tables map CFI code characters to their human-readable descriptions for each position.
51
+
52
+ ## Models Used
53
+
54
+ This project was developed using Claude AI:
55
+
56
+ - Claude Opus 4.6
57
+ - Claude Sonnet 4.6
58
+ - Claude Haiku 4.5
@@ -0,0 +1,8 @@
1
+ cfi_decoder/__init__.py,sha256=ddWAJcJk4IlbG72pKPMZS4Lmd1UnyysBpkpwWTBiCb8,50
2
+ cfi_decoder/_data.py,sha256=FuS8tQ1hlmyKTRaCM1kS2jEFRgieMXEJTUrejPfd72A,28165
3
+ cfi_decoder/_decode.py,sha256=ZbT5E7I97zZTt6_XBcQJAzM4ktvHgCotQNVbeuVcKr8,1800
4
+ cfi_decoder/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ cfi_decoder-0.1.0.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
6
+ cfi_decoder-0.1.0.dist-info/WHEEL,sha256=s_zqWxHFEH8b58BCtf46hFCqPaISurdB9R1XJ8za6XI,80
7
+ cfi_decoder-0.1.0.dist-info/METADATA,sha256=UHdrBegdKQtDRNVts6UPsh3W3rtlTpRaoKmqUqEcD5w,2183
8
+ cfi_decoder-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: uv 0.11.6
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any