llamazure.rid : Resource IDs you can use
The llamazure.rid package provides a usable resource ID parser.
Benefits:
- quickly get the actual resource targetted and not the basemost resource (for example, easily get a lock and not the resource it's on)
- differentiate subscriptions, resource groups, resources, and child resources
- preserve resource tree while keeping resource group and subscription information available
- automatic case normalisation (seriously what's up with that)
This library includes several implementations of resource ID parsing. rid produces object-based resources; mp produces materialised-path based resources. Which to use? The mp makes it easy to traverse the bodies of Azure resources to reference other Azure resources. For example, if you have a Microsoft.Network/virtualNetworks and you want to show all of its ipConfigurations: You might get the virtualNetwork, list all ipConfigurations, and then join on the resource ID. In contrast, rid is harder to traverse azure resource data but easier to traverse the hierarchy. For example, it is very easy to get information about the target of a lock from the lock itself. It's also convenient to place rid into a tree structure, such as llamazure.rid.tresource; while mp use the materialised-path format for representing tree structures in relational systems.
rid : object-based resources
Usage
Just call parse to turn resource IDs into objects. That's it. The resource you want is the result, all the other information is chained in.
You can also ask for the chain directly using the parse_chain method. This returns a list of all the parents of the resource, starting at the subscription. Having the chain is useful if you intend to use the hierarchy of resources, like pushing resources into a Tresource for the tree structure.
You'll know if a resource is a child resource if it has a non-None parent resource. It is a root resource if parent is None.
Examples
from llamazure.rid.rid import parse, Resource, ResourceGroup, Subscription
p = parse("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example/providers/Microsoft.Example/example_type/example_resource")
assert p == Resource(provider='microsoft.example',
res_type='example_type',
name='example_resource',
rg=ResourceGroup(name='example',
sub=Subscription(uuid='00000000-0000-0000-0000-000000000000')),
sub=Subscription(uuid='00000000-0000-0000-0000-000000000000'),
parent=None)
mp : materialised-path-based resources
Usage
Just call parse to turn resource IDs into tuples of the path and the object. That's it.
You can also get the parsed chain directly by using the parse_chain method. Having the chain might be less useful for mp than for rid. Materialised paths are often used to avoid having to join on parents, so having the parents may not be as helpful.
Examples
Parse the resource ID:
from llamazure.rid.mp import parse, Resource
path, resource = parse("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example/providers/Microsoft.Example/example_type/example_resource")
assert resource == Resource(
path=path,
provider='microsoft.example',
res_type='example_type',
name='example_resource',
rg="/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/example",
sub="/subscriptions/00000000-0000-0000-0000-000000000000"
)
Parse many resource IDs and convert them into a lookup table:
from llamazure.rid.mp import parse
resource_ids = [f"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example/providers/Microsoft.Example/example_type/example_resource{i}" for i in range(10)]
resources = dict(parse(rid) for rid in resource_ids)
Design notes
Denormalised RG and Subscription
Denormalising the data by injecting the rg and subscription in every resource in the chain increases the usability. You can get this information directly, without having to walk up the tree. Also, not every resource has a resource group, so the data model already has to be looser to accomodate that fact. Denormalising also helps with the implementation somewhat, since we can just push forward with None in the resource group.
Classes for modelling
I used classes to model the type of object you get back. Sometimes this is annoying, like when you can get a Resource or a SubResource. But that's the reality of Azure.
Metadata
Release files for llamazure.rid 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| llamazure_rid-0.1.1.tar.gz | 8.0 kB | Without provenance | Details for llamazure_rid-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| llamazure_rid-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for llamazure_rid-0.1.1-py3-none-any.whl |
Total release size: 15.6 kB
Release files / llamazure_rid-0.1.1.tar.gz
| Download URL | llamazure_rid-0.1.1.tar.gz |
|---|---|
| Size | 8.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ca84a32b69eaa6e5d864faddabbf31d9fac120864605793e4be3d14145835165
|
|
BLAKE2b-256 checksum How to use checksums |
7f86b0d5d6d317e535237e571a9e581eb19e8dd40154729e994f2dd3c3c5f72e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / llamazure_rid-0.1.1-py3-none-any.whl
| Download URL | llamazure_rid-0.1.1-py3-none-any.whl |
|---|---|
| Size | 7.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
27ef19e31667384f0523336d318566f637c18a8aea7893dbc3defa7c40a1b94b
|
|
BLAKE2b-256 checksum How to use checksums |
df4483a98fedad8ba1d4867739f3c02f6bdd5259c148817b37d75fcd400ea3a7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Security for llamazure.rid 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.