Skip to main content

alpacloud.eztag

eztag helps you easily filter things by tags.

Usage

Filtering in code

You can directly invoke the filters as functions. For example:

from alpacloud.eztag.tag import TagSet

@dataclass
class Snippet:
    name: str
    content: str
    tags: TagSet

you can filter them with convenient syntax:

filter(lambda s: s.tags.has("python"), snippets)

There are several filter functions available:

  • has : check if a TagSet has a tag
  • match : check if a TagSet has a key with a value
  • rematch : check if a TagSet has a key with a value that matches a regex
  • contains : check if a TagSet has a key whose value contains a substring

Filtering external data

If your objects don't have tags, you can associate tag data with them using Selector:

from alpacloud.eztag.logic import TagMatch
from alpacloud.eztag.selector import Selector
from alpacloud.eztag.tag import TagSet

tasks = Selector([
    (TagSet.from_dict({"env":"prd", "dangerous": "true"}), task0),
    (TagSet.from_dict({"env":"stg", "dangerous": "false"}), task1),
])

dangerous_tasks = tasks.select(TagMatch("dangerous", "true"))

Filtering from the CLI

eztag allows you to input filters in a simple language from the CLI. You can build this filtering into your own tools.

import click

from alpacloud.eztag.parser import Parser, transformer
from alpacloud.eztag.selector import Selector

tagged_tasks = Selector(...)

@click.command()
@click.argument("filter")
def cli(filter):
    expr = transformer.transform(Parser(filter).parse())
    selected_tasks = tagged_tasks.select(expr)

    for task in selected_tasks:
        task.run()

Then you can invoke it like this:

task-run --filter 'and(match(env, prd), re(name, /cert.*/)'

CLI filter usage

Filter syntax is:

regex_literal := "/" regex "/"
string_literal := any characters except "(),/" and spaces
expr := identifier(expr [, expr])* | regex_literal | string_literal
identifier := "and" | "or" | "not" | "has" | "match" | "re" | "contains"

the operations are:

  • and : logical AND
  • or : logical OR
  • not : logical NOT
  • has : check if a tag has a key
  • match : check if a tag has a key with a value
  • re : check if a tag has a key with a value that matches a regex
  • contains : check if a tag has a key whose value contains a substring

Advanced usage

Adding custom filters or operators

You can add your own filters or operators to streamline your usecase. For example, if you shard your tasks, you can add a filter to run only on a specific shard and then filter with AND(MATCH(env, prd), SHARD(5)) for example.

  1. Implement your filter as a subclass of alpacloud.eztag.logic.Expr

    from dataclasses import dataclass
    from alpacloud.eztag.logic import Expr
    
    @dataclass(frozen=True)
    class Shard(Expr):
        """Run tasks with this shard identifier"""
        shard: int
    
        def check(self, tags) -> bool:
            return tags.contains("shard", str(self.shard))
    
  2. Register your filter in the transformer dictionary:

    from alpacloud.eztag.transformer import transformer, TokenTransformer, TokenTransformation
    
    my_transformer = transformer.extended({
        "SHARD": TokenTransformation("SHARD", Shard, args=["shard"]),
    })
    

Metadata

Release files for alpacloud-eztag 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for alpacloud-eztag 0.1.0
File Size Uploaded Provenance Actions
alpacloud_eztag-0.1.0.tar.gz 7.9 kB Without provenance Details for alpacloud_eztag-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for alpacloud-eztag 0.1.0
File Interpreter ABI Platform Actions
alpacloud_eztag-0.1.0-py3-none-any.whl Python 3 none any Details for alpacloud_eztag-0.1.0-py3-none-any.whl

Total release size: 16.0 kB

Release files / alpacloud_eztag-0.1.0.tar.gz

Download URL alpacloud_eztag-0.1.0.tar.gz
Size 7.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e5ce37cc06501fddb8f186b2610d95b3ad62c3abddd08b28726561e8a0da95d9
BLAKE2b-256 checksum
How to use checksums
7d1b77edf2c162bfd0bf5abb9527f0da9300d087f4a95490caebf516d716256d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / alpacloud_eztag-0.1.0-py3-none-any.whl

Download URL alpacloud_eztag-0.1.0-py3-none-any.whl
Size 8.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
82398200e806677e7418fc61dfea3a72ba65e6a79dc12086b00b0feb82d737ca
BLAKE2b-256 checksum
How to use checksums
db7ae0efb9512ff985f90dd292ad01cc70ad208cf9012893a7a1ae102657b8e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Security for alpacloud-eztag 0.1.0

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page