tessl install tessl/pypi-furl@2.1.0URL manipulation made simple.
Agent Success
Agent success rate when using this tile
65%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.59x
Baseline
Agent success rate without this tile
41%
Transforms a base URL string according to a structured recipe of additive, overriding, and removal steps on its path, query string, and optional fragment. Operations run in order: append path segments, add query entries, override specific query keys, remove disallowed query keys, then optionally repeat the same add/set/remove sequence for fragment path/query while preserving any untouched components. String values for query/fragment entries count as single values; sequences of strings create repeated parameters in the given order. Unspecified URL components remain unchanged from the base URL.
https://example.com/base?foo=1&keep=ok, with path_segments=["dashboards","sales"], query_appends={"tag": ["north","west"], "keep": "ok"}, query_overrides={"foo": "9", "view": "summary"}, query_removals=["keep"], and no fragment recipe, the function returns https://example.com/base/dashboards/sales?foo=9&view=summary&tag=north&tag=west. @testhttps://service.test/app?mode=old&token=x&drop=1, with path_segments=["reports"], query_appends={"token": ["x","y"]}, query_overrides={"mode": "new"}, query_removals=["drop","token"], and no fragment recipe, the function returns https://service.test/app/reports?mode=new. @testhttps://shop.example.com/products?session=keep#filters?color=red&debug=1, with path_segments=["summer"], query_appends={"promo": "flash"}, query_overrides={"session": "stay"}, query_removals=["session"], and a fragment recipe of {"path_segments":["active"],"add_query":{"color":["blue"]},"set_query":{"sort":"price"},"remove_query":["debug"]}, the function returns https://shop.example.com/products/summer?session=stay&promo=flash#filters/active?color=red&color=blue&sort=price. @test@generates
from typing import Iterable, Mapping, Optional, Sequence, TypedDict, Union
QueryValue = Union[str, Sequence[str]]
QueryMap = Mapping[str, QueryValue]
class FragmentRecipe(TypedDict, total=False):
path_segments: Sequence[str]
add_query: QueryMap
set_query: QueryMap
remove_query: Iterable[str]
def apply_url_recipe(
base_url: str,
path_segments: Sequence[str],
query_appends: QueryMap,
query_overrides: QueryMap,
query_removals: Iterable[str],
fragment: Optional[FragmentRecipe] = None,
) -> str:
"""Return a URL string after applying additive, overriding, and removal steps to path, query, and fragment."""Provides URL parsing and inline component mutation helpers.