arnmatch 2026.1.3__tar.gz → 2026.2.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.
Files changed (49) hide show
  1. arnmatch-2026.2.0/AGENTS.md +299 -0
  2. {arnmatch-2026.1.3 → arnmatch-2026.2.0}/CLAUDE.md +1 -1
  3. {arnmatch-2026.1.3 → arnmatch-2026.2.0}/Makefile +9 -1
  4. {arnmatch-2026.1.3 → arnmatch-2026.2.0}/PKG-INFO +1 -1
  5. arnmatch-2026.2.0/codegen/.gitignore +2 -0
  6. arnmatch-2026.2.0/codegen/Makefile +14 -0
  7. arnmatch-2026.2.0/codegen/cache/CloudFormationResourceSpecification.json +1 -0
  8. arnmatch-2026.2.0/codegen/cache/CloudFormationResources.json +1971 -0
  9. arnmatch-2026.2.0/codegen/cache/CloudFormationServices.json +857 -0
  10. arnmatch-2026.2.0/codegen/cache/SDKServices.json +1051 -0
  11. arnmatch-2026.2.0/codegen/codegen.py +296 -0
  12. arnmatch-2026.2.0/codegen/codegen_python.py +136 -0
  13. arnmatch-2026.2.0/codegen/index_arn.py +152 -0
  14. arnmatch-2026.2.0/codegen/index_cfn.py +150 -0
  15. arnmatch-2026.2.0/codegen/index_cfn_resources.py +128 -0
  16. arnmatch-2026.2.0/codegen/index_sdk.py +103 -0
  17. arnmatch-2026.2.0/codegen/index_sdk_resources.py +47 -0
  18. arnmatch-2026.2.0/codegen/rules/arn_excludes.json +9 -0
  19. arnmatch-2026.2.0/codegen/rules/arn_excludes_resources.json +15 -0
  20. arnmatch-2026.2.0/codegen/rules/arn_includes.json +12 -0
  21. arnmatch-2026.2.0/codegen/rules/arn_overrides.json +42 -0
  22. arnmatch-2026.2.0/codegen/rules/cfn_excludes.json +24 -0
  23. arnmatch-2026.2.0/codegen/rules/cfn_overrides.json +22 -0
  24. arnmatch-2026.2.0/codegen/rules/cfn_resources_excludes.json +847 -0
  25. arnmatch-2026.2.0/codegen/rules/cfn_resources_overrides.json +203 -0
  26. arnmatch-2026.2.0/codegen/rules/lowercase_transforms.json +358 -0
  27. arnmatch-2026.2.0/codegen/rules/sdk_excludes.json +48 -0
  28. arnmatch-2026.2.0/codegen/rules/sdk_overrides.json +20 -0
  29. arnmatch-2026.2.0/codegen/rules/sdk_resources_defaults.json +38 -0
  30. arnmatch-2026.2.0/codegen/rules/sdk_resources_overrides.json +115 -0
  31. arnmatch-2026.2.0/codegen/transform.py +125 -0
  32. arnmatch-2026.2.0/codegen/utils.py +54 -0
  33. arnmatch-2026.2.0/docs/CloudFormation.md +234 -0
  34. {arnmatch-2026.1.3 → arnmatch-2026.2.0}/pyproject.toml +4 -0
  35. {arnmatch-2026.1.3 → arnmatch-2026.2.0}/src/arnmatch/__init__.py +11 -31
  36. arnmatch-2026.2.0/src/arnmatch/arn_patterns.py +3155 -0
  37. arnmatch-2026.2.0/tests/integration/test_resource_explorer.py +137 -0
  38. {arnmatch-2026.1.3 → arnmatch-2026.2.0}/tests/test_arnmatch.py +27 -15
  39. arnmatch-2026.1.3/codegen/.gitignore +0 -1
  40. arnmatch-2026.1.3/codegen/codegen.py +0 -347
  41. arnmatch-2026.1.3/codegen/index_sdk.py +0 -194
  42. arnmatch-2026.1.3/codegen/index_sdk_resources.py +0 -199
  43. arnmatch-2026.1.3/src/arnmatch/arn_patterns.py +0 -3213
  44. {arnmatch-2026.1.3 → arnmatch-2026.2.0}/.github/workflows/workflow.yml +0 -0
  45. {arnmatch-2026.1.3 → arnmatch-2026.2.0}/.gitignore +0 -0
  46. {arnmatch-2026.1.3 → arnmatch-2026.2.0}/.python-version +0 -0
  47. {arnmatch-2026.1.3 → arnmatch-2026.2.0}/README.md +0 -0
  48. {arnmatch-2026.1.3 → arnmatch-2026.2.0}/codegen/scraper.py +0 -0
  49. {arnmatch-2026.1.3 → arnmatch-2026.2.0}/uv.lock +0 -0
@@ -0,0 +1,299 @@
1
+ # arnmatch - AI Agent Guide
2
+
3
+ ## Project Overview
4
+
5
+ arnmatch is a zero-dependency Python library that parses AWS ARNs (Amazon Resource Names) into structured data. It supports 300+ AWS services and 2000+ resource types. The library provides both a programmatic API and a CLI interface.
6
+
7
+ Key characteristics:
8
+ - **Zero runtime dependencies** - only standard library
9
+ - **Auto-generated patterns** - scraped from AWS official documentation
10
+ - **Dual interface** - CLI (`arnmatch <arn>`) and library (`arnmatch.arnmatch()`)
11
+ - **Versioning** - CalVer format `YYYY.0M.MICRO` (e.g., `2026.01.3`)
12
+
13
+ ## Technology Stack
14
+
15
+ - **Language**: Python 3.10+
16
+ - **Build System**: [hatchling](https://hatch.pypa.io/)
17
+ - **Package Manager**: [uv](https://github.com/astral-sh/uv) (required for development)
18
+ - **Linter**: [ruff](https://docs.astral.sh/ruff/)
19
+ - **Testing**: pytest
20
+
21
+ ## Project Structure
22
+
23
+ ```
24
+ ├── src/arnmatch/ # Core library (zero runtime deps)
25
+ │ ├── __init__.py # Main module: ARN dataclass, arnmatch() function
26
+ │ └── arn_patterns.py # GENERATED FILE - compiled regex patterns
27
+ ├── codegen/ # Code generation (has external deps)
28
+ │ ├── scraper.py # Scrapes AWS service authorization reference pages
29
+ │ ├── codegen.py # Main code generator
30
+ │ ├── index_arn.py # Processes raw ARN resources, applies overrides
31
+ │ ├── index_sdk.py # Maps ARN service names to boto3 client names
32
+ │ ├── index_sdk_resources.py # Resource-level SDK client mappings
33
+ │ ├── index_cfn.py # Maps services to CloudFormation resource types
34
+ │ ├── index_cfn_resources.py # Maps ARN resources to CFN resource types
35
+ │ ├── utils.py # Shared utilities (botocore metadata loader)
36
+ │ └── build/ # Build output (generated patterns)
37
+ │ └── arn_patterns.py # Generated patterns (copied to src/)
38
+ ├── tests/ # pytest test suite
39
+ │ └── test_arnmatch.py # Tests for various AWS services
40
+ ├── Makefile # Build automation
41
+ ├── pyproject.toml # Project configuration
42
+ └── .cache/ # Scraper cache (joblib)
43
+ ```
44
+
45
+ ## Build and Development Commands
46
+
47
+ All commands use `make` and require `uv` to be installed:
48
+
49
+ ```bash
50
+ # Linting
51
+ make lint # Run ruff linter
52
+
53
+ # Testing
54
+ make test # Run pytest tests
55
+ make check # Run both lint and test
56
+
57
+ # Building
58
+ make build # Copy generated patterns + build wheel/tarball
59
+ # NOTE: This copies codegen/build/arn_patterns.py to src/arnmatch/
60
+
61
+ # Publishing
62
+ make publish # Build and upload to PyPI (requires credentials)
63
+
64
+ # Cleanup
65
+ make clean # Remove build artifacts
66
+ ```
67
+
68
+ ## Code Generation Workflow
69
+
70
+ The ARN patterns are auto-generated from AWS documentation. To regenerate:
71
+
72
+ ```bash
73
+ cd codegen && uv run codegen.py
74
+ ```
75
+
76
+ This will:
77
+ 1. Scrape AWS service authorization reference pages (cached with joblib)
78
+ 2. Process resources, apply overrides, filter, deduplicate
79
+ 3. Build SDK service mappings using botocore metadata
80
+ 4. Build CloudFormation resource mappings
81
+ 5. Generate `codegen/build/arn_patterns.py`
82
+
83
+ After regeneration, run `make build` to copy the patterns to `src/arnmatch/`.
84
+
85
+ ### Code Generation Architecture
86
+
87
+ **Data Flow:**
88
+ ```
89
+ AWS Docs → scraper.py → raw resources → index_arn.py → processed resources
90
+
91
+ botocore metadata → index_sdk.py → SDK mappings → codegen.py
92
+
93
+ CFN spec → index_cfn.py → CFN mappings → index_cfn_resources.py
94
+
95
+ codegen/build/arn_patterns.py
96
+
97
+ make build
98
+
99
+ src/arnmatch/arn_patterns.py
100
+ ```
101
+
102
+ **Key Components:**
103
+
104
+ | File | Purpose |
105
+ |------|---------|
106
+ | `scraper.py` | Fetches AWS docs, extracts service prefixes and resource patterns |
107
+ | `index_arn.py` | Processes resources: deduplicates, sorts by specificity, applies `PATTERN_OVERRIDES` and `PATTERN_INCLUDES` |
108
+ | `index_sdk.py` | Maps ARN service names to boto3 client names using botocore metadata |
109
+ | `index_sdk_resources.py` | Defines `DEFAULT_SERVICE` and `OVERRIDE_SERVICE` for multi-SDK services |
110
+ | `index_cfn.py` | Maps services to CloudFormation resource types using CFN spec |
111
+ | `index_cfn_resources.py` | Maps ARN resource types to CFN resource types |
112
+ | `codegen.py` | Main generator, produces Python file with compiled regex patterns |
113
+
114
+ ### Important Override Files
115
+
116
+ When AWS docs have errors or omissions, edit these in `codegen/`:
117
+
118
+ - **`index_arn.py:PATTERN_OVERRIDES`** - Fix incorrect ARN patterns in AWS docs
119
+ - **`index_arn.py:PATTERN_INCLUDES`** - Add patterns not in AWS docs (e.g., EKS k8s resources)
120
+ - **`index_sdk.py:OVERRIDES`** - Manual ARN service → SDK client mappings
121
+ - **`index_sdk.py:EXCLUDES_*`** - Services to exclude (discontinued, console-only, no SDK)
122
+ - **`index_sdk_resources.py:DEFAULT_SERVICE`** - Default SDK for multi-SDK services
123
+ - **`index_sdk_resources.py:OVERRIDE_SERVICE`** - Resource-level SDK overrides
124
+ - **`index_cfn.py:OVERRIDES`** - Manual CFN service → SDK service mappings
125
+
126
+ ## Core Library Architecture
127
+
128
+ ### Main API (`src/arnmatch/__init__.py`)
129
+
130
+ ```python
131
+ from arnmatch import arnmatch
132
+
133
+ result = arnmatch("arn:aws:lambda:us-east-1:123456789012:function:my-function")
134
+
135
+ # Available attributes:
136
+ result.aws_partition # "aws"
137
+ result.aws_service # "lambda"
138
+ result.aws_region # "us-east-1"
139
+ result.aws_account # "123456789012"
140
+ result.resource_type # "function" (canonical)
141
+ result.resource_types # ["function"] (all known names)
142
+ result.attributes # {"FunctionName": "my-function", ...}
143
+
144
+ # Properties (computed):
145
+ result.resource_id # "my-function" (heuristic: prefers *Id, then *Name)
146
+ result.resource_name # "my-function" (heuristic: prefers *Name, falls back to resource_id)
147
+ result.aws_sdk_services # ["lambda"] (all possible boto3 clients)
148
+ result.aws_sdk_service # "lambda" (specific client for this resource)
149
+ result.cloudformation_resource # "AWS::Lambda::Function" or None
150
+ ```
151
+
152
+ ### ARN Dataclass
153
+
154
+ The `ARN` dataclass is frozen and stores:
155
+ - `aws_partition`, `aws_service`, `aws_region`, `aws_account` - ARN components
156
+ - `resource_type` - canonical type from AWS docs
157
+ - `resource_types` - all known aliases for this type
158
+ - `attributes` - dict of all regex capture groups
159
+
160
+ Properties use `@cached_property` for lazy evaluation.
161
+
162
+ ### Pattern Matching Algorithm
163
+
164
+ 1. Split ARN by `:` into 6 parts (arn, partition, service, region, account, resource)
165
+ 2. Look up service in `ARN_PATTERNS` dict (O(1))
166
+ 3. Iterate through patterns for that service (most specific first)
167
+ 4. Return first match with all capture groups
168
+
169
+ Pattern ordering is critical - patterns are sorted by specificity:
170
+ - More segments come first
171
+ - Literal segments come before wildcards
172
+ - Variables come before wildcards
173
+
174
+ ## Testing Strategy
175
+
176
+ Tests are in `tests/test_arnmatch.py` and use pytest:
177
+
178
+ ```bash
179
+ make test
180
+ ```
181
+
182
+ Test patterns:
183
+ - Each major service has a test function (e.g., `test_lambda()`, `test_s3()`)
184
+ - Tests verify: resource_type, attributes, SDK mappings, CFN mappings
185
+ - Edge cases: multi-SDK services, resource-level overrides
186
+
187
+ When adding new features or fixing bugs, add corresponding test cases.
188
+
189
+ ## Development Guidelines
190
+
191
+ ### Code Style
192
+
193
+ - Follow existing code style (ruff enforces this)
194
+ - Run `make lint` before committing
195
+ - Use type hints where appropriate
196
+ - Document public APIs with docstrings
197
+
198
+ ### Adding New Patterns
199
+
200
+ If AWS docs are missing a pattern:
201
+
202
+ 1. Add to `codegen/index_arn.py:PATTERN_INCLUDES`:
203
+ ```python
204
+ PATTERN_INCLUDES = [
205
+ # (service, arn_pattern, resource_type)
206
+ ("eks", "arn:${Partition}:eks:${Region}:${Account}:pod/${ClusterName}/${Namespace}/${PodName}/${UUID}", "pod"),
207
+ ]
208
+ ```
209
+
210
+ 2. Regenerate: `cd codegen && uv run codegen.py`
211
+ 3. Rebuild: `make build`
212
+ 4. Test: `make test`
213
+
214
+ ### Fixing Pattern Issues
215
+
216
+ If AWS docs have incorrect patterns (e.g., wildcards instead of capture groups):
217
+
218
+ 1. Add to `codegen/index_arn.py:PATTERN_OVERRIDES`:
219
+ ```python
220
+ PATTERN_OVERRIDES = {
221
+ ("service", "resource-type"): "arn:${Partition}:service:${Region}:${Account}:resource/${ResourceId}",
222
+ }
223
+ ```
224
+
225
+ ### Version Updates
226
+
227
+ Version is in `src/arnmatch/__init__.py:__version__` (CalVer format).
228
+
229
+ Update this when:
230
+ - Regenerating patterns (if AWS docs changed)
231
+ - Adding new features
232
+ - Fixing bugs
233
+
234
+ ## Key Design Decisions
235
+
236
+ 1. **Zero runtime dependencies** - Only standard library in `src/arnmatch/`
237
+ 2. **Compiled regex patterns** - Generated once, not parsed at runtime
238
+ 3. **Service-indexed patterns** - O(1) lookup before pattern matching
239
+ 4. **Specificity-based sorting** - More specific patterns match first
240
+ 5. **Multi-SDK support** - Some services map to multiple boto3 clients (e.g., `rds` → `["rds", "docdb", "neptune"]`)
241
+
242
+ ## Common Tasks
243
+
244
+ ### Test a specific ARN locally
245
+
246
+ ```bash
247
+ uv run arnmatch "arn:aws:lambda:us-east-1:123456789012:function:my-function"
248
+ ```
249
+
250
+ ### Regenerate all patterns from AWS docs
251
+
252
+ ```bash
253
+ cd codegen && uv run codegen.py
254
+ make build
255
+ make test
256
+ ```
257
+
258
+ ### Clear scraper cache
259
+
260
+ If AWS docs changed significantly and caching causes issues:
261
+
262
+ ```bash
263
+ rm -rf .cache/
264
+ ```
265
+
266
+ ### Add support for a new service
267
+
268
+ Usually automatic via code generation. If the service has special cases:
269
+
270
+ 1. Check `codegen/index_sdk.py` - add override if SDK name differs
271
+ 2. Check `codegen/index_sdk_resources.py` - add to `DEFAULT_SERVICE` or `OVERRIDE_SERVICE` if multi-SDK
272
+ 3. Check `codegen/index_cfn.py` - add to `OVERRIDES` if CFN service name differs
273
+ 4. Regenerate and test
274
+
275
+ ## Security Considerations
276
+
277
+ - The library only parses ARN strings, never makes AWS API calls
278
+ - No credentials or sensitive data is handled
279
+ - Generated patterns come from official AWS documentation
280
+ - The scraper only reads public AWS documentation pages
281
+
282
+ ## Troubleshooting
283
+
284
+ **Issue**: Pattern not matching
285
+ - Check if pattern exists in `codegen/build/arn_resources.json`
286
+ - Check `PATTERN_OVERRIDES` if AWS docs use wildcards
287
+ - Check `PATTERN_INCLUDES` if pattern is missing from docs
288
+
289
+ **Issue**: Wrong SDK client returned
290
+ - Check `index_sdk.py:OVERRIDES` for service-level mapping
291
+ - Check `index_sdk_resources.py:OVERRIDE_SERVICE` for resource-level mapping
292
+
293
+ **Issue**: Tests fail after regeneration
294
+ - AWS docs may have changed - verify changes are correct
295
+ - Some services may have been discontinued - check `EXCLUDES_*` sets
296
+
297
+ **Issue**: Import errors
298
+ - Ensure `make build` was run (copies patterns to src/)
299
+ - Check that `uv sync` was run to install dependencies
@@ -19,7 +19,7 @@ make clean # Remove build artifacts
19
19
 
20
20
  Run codegen to regenerate patterns from AWS docs:
21
21
  ```bash
22
- cd codegen && uv run codegen.py
22
+ uv run codegen/codegen.py
23
23
  ```
24
24
 
25
25
  Test locally:
@@ -12,9 +12,17 @@ lint: ## Run linter
12
12
  test: ## Run tests
13
13
  uv run pytest tests/
14
14
 
15
+ .PHONY: test-integration
16
+ test-integration: ## Run integration test (requires AWS credentials + Resource Explorer)
17
+ uv run --with boto3 tests/integration/test_resource_explorer.py
18
+
15
19
  .PHONY: check
16
20
  check: lint test ## Run lint and test
17
21
 
22
+ .PHONY: generate
23
+ generate: ## Generate ARN patterns
24
+ $(MAKE) -C codegen
25
+
18
26
  .PHONY: build
19
27
  build: ## Build package
20
28
  cp codegen/build/arn_patterns.py src/arnmatch/arn_patterns.py
@@ -26,4 +34,4 @@ publish: build ## Publish package to PyPI
26
34
 
27
35
  .PHONY: clean
28
36
  clean: ## Clean build artifacts
29
- rm -rf dist/ __pycache__/ .pytest_cache/ .ruff_cache/
37
+ rm -rf dist/ __pycache__/ .pytest_cache/ .ruff_cache/ .cache/
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: arnmatch
3
- Version: 2026.1.3
3
+ Version: 2026.2.0
4
4
  Summary: Parse AWS ARNs into structured data (2000+ resource types)
5
5
  Author-email: Andrey Gubarev <andrey@andreygubarev.com>
6
6
  Requires-Python: >=3.10
@@ -0,0 +1,2 @@
1
+ !build
2
+ debug_*.py
@@ -0,0 +1,14 @@
1
+ .DEFAULT_GOAL := build
2
+
3
+ .PHONY: build
4
+ build: clean build/arn_patterns.yaml build/arn_patterns.py
5
+
6
+ build/arn_patterns.yaml:
7
+ uv run codegen.py
8
+
9
+ build/arn_patterns.py: build/arn_patterns.yaml
10
+ uv run codegen_python.py
11
+
12
+ .PHONY: clean
13
+ clean:
14
+ rm -rf build/