Skip to main content

arnmatch - parse AWS ARNs into structured data

Project description

arnmatch

Parse AWS ARNs into structured data.

Python 3.10+

Features

  • Zero runtime dependencies
  • 300+ AWS services, 2000+ resource types supported
  • Patterns auto-generated from AWS official documentation
  • CLI and library interface
  • Extracts resource type, ID, and name with smart heuristics

Installation

pip install arnmatch

Quick Start

CLI

$ arnmatch "arn:aws:lambda:us-east-1:123456789012:function:my-function"
aws_service: lambda
aws_region: us-east-1
aws_account: 123456789012
resource_type: function
resource_id: my-function
resource_name: my-function

Library

from arnmatch import arnmatch

arn = "arn:aws:lambda:us-east-1:123456789012:function:my-function"
result = arnmatch(arn)

print(result.aws_service)    # lambda
print(result.aws_region)     # us-east-1
print(result.aws_account)    # 123456789012
print(result.resource_type)  # function
print(result.resource_id)    # my-function
print(result.resource_name)  # my-function
print(result.attributes)     # {'Partition': 'aws', 'Region': 'us-east-1', ...}

API Reference

arnmatch(arn: str) -> ARN

Parse an ARN string and return structured data.

Raises ARNError if the ARN format is invalid or no pattern matches.

ARN

Dataclass with parsed ARN components:

Field Type Description
aws_partition str AWS partition (aws, aws-cn, aws-us-gov)
aws_service str AWS service name
aws_region str AWS region (may be empty for global resources)
aws_account str AWS account ID
resource_type str Canonical resource type from AWS docs
resource_types list[str] All known names for this resource type
attributes dict[str, str] All captured attributes from the pattern

Properties:

Property Description
resource_id Resource identifier (prefers groups ending in Id, falls back to Name, then last group)
resource_name Resource name (prefers groups ending in Name, falls back to resource_id)

ARNError

Exception raised when ARN parsing fails. Inherits from ValueError.

Development

Prerequisites: uv

make lint       # Run ruff linter
make build      # Build wheel and tarball
make publish    # Build and upload to PyPI
make clean      # Remove build artifacts

Regenerate patterns from AWS docs:

cd codegen && uv run codegen.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

arnmatch-0.3.0.tar.gz (60.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

arnmatch-0.3.0-py3-none-any.whl (40.3 kB view details)

Uploaded Python 3

File details

Details for the file arnmatch-0.3.0.tar.gz.

File metadata

  • Download URL: arnmatch-0.3.0.tar.gz
  • Upload date:
  • Size: 60.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for arnmatch-0.3.0.tar.gz
Algorithm Hash digest
SHA256 013df1d42e30f37569b8eb781f766d2943f7fc53c43e3050674cbfa7d492e034
MD5 51df57689627264a49ef0b066d5c0329
BLAKE2b-256 bbe843e8c7d584973c39e198d0008cc72b6506fe442933eecfd1e8646dfa615b

See more details on using hashes here.

File details

Details for the file arnmatch-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: arnmatch-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 40.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for arnmatch-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c0dd6f70985a98ac3c18826b00221043f15e72d983b81b5bb2eaee2f77b593fc
MD5 0ea5e8160b06a6b049726327bc9d61e1
BLAKE2b-256 9f3d4cc7e42df4a7f022f7492534aa4c657539b0106acb37bb46504dc4a554b5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page