Filters
environment¶
| Name | Description |
|---|---|
| render_template | Render a loaded template (or a block of a template). |
| render_string | Render a template string. |
| render_file | Helper to directly render a template from filesystem. |
| evaluate | Evaluate python code and return the caught stdout + return value of last line. |
file¶
| Name | Description |
|---|---|
| filesizeformat | Format the value like a 'human-readable' file size (i.e. 13 kB, |
format¶
| Name | Description |
|---|---|
| repr | Return the canonical string representation of the object. |
| slugify | Create a slug for given text. |
| dirname_to_title | Return a page tile obtained from a directory name. |
| pformat | Format a Python object into a pretty-printed representation. |
| split_url | Split a URL into its parts (and optionally return a specific part). |
| format_code | Format code to given line length using black. |
| extract_body | Get body of source code of given function / class. |
| format_signature | Format signature of a callable. |
| format_filter_signature | Create a signature for a jinja filter based on filter name and callable. |
| format | Apply the given values to a printf-style_ format string, like |
| pprint | Pretty print a variable. Useful for debugging. |
html¶
| Name | Description |
|---|---|
| html_link | Create a html link. |
| wrap_in_elem | Wrap given text in an HTML/XML tag (with attributes). |
| format_js_map | Return JS map str for given dictionary. |
| format_css_rule | Format a nested dictionary as CSS rule. |
| svg_to_data_uri | Wrap svg as data URL. |
| clean_svg | Strip off unwanted stuff from svg text which might be added by external libs. |
| format_xml | (Pretty)print given XML. |
| ansi2html | Convert ansi string to colored HTML. |
| relative_url | Compute the relative path from URL A to URL B. |
| relative_url_mkdocs | Return given url relative to other (MkDocs implementation). |
| normalize_url | Return a URL relative to the given url or using the base. |
| url_to_b64 | Convert an image URL to a base64-encoded string. |
| inject_javascript | Injects JavaScript code into an HTML string or bytes object. |
| urlencode | Quote data for use in a URL path or query using UTF-8. |
| urlize | Convert URLs in text into clickable links. |
| xmlattr | Create an SGML/XML attribute string based on the items in a dict. |
icons¶
| Name | Description |
|---|---|
| get_favicon | Return a favicon URL for the given URL. |
| get_icon_svg | Return svg for given pyconify icon key. |
| get_pyconify_key | Convert given string to a pyconify key. |
| get_path_icon | Get the icon mapping for a given file path or directory. |
| get_path_ascii_icon | Get an ASCII icon for a given file path based on its type. |
inspect¶
| Name | Description |
|---|---|
| get_doc | Get doc for given object. |
| get_argspec | Return a cleaned-up FullArgSpec for given callable. |
| get_annotations | Compute the annotations dict for an object. |
| list_subclasses | Return list of all subclasses of given klass. |
| list_baseclasses | Return list of all baseclasses of given klass. |
| get_deprecated_message | Return deprecated message (created by deprecated decorator). |
| get_source | Cached wrapper for inspect.getsource. |
| get_source_lines | Cached wrapper for inspect.getsourcelines. |
| get_signature | Cached wrapper for inspect.signature. |
| get_file | Cached wrapper for inspect.getfile. |
| get_structure_map | Generate a textual tree representation of Python code structure. |
iter¶
| Name | Description |
|---|---|
| batched | Batch data into tuples of length n. The last batch may be shorter. |
| groupby_plus | Group given iterable using given group function. |
| chain | Chain all given iterators. |
| combinations | Return successive r-length combinations of elements in the iterable. |
| combinations_with_replacement | Return successive r-length combinations of elements in the iterable allowing individual elements to have successive repeats. |
| compress | Return data elements corresponding to true selector elements. |
| islice | Make an iterator that returns selected elements from the iterable. |
| groupby_first_letter | Group given iterable by first letter. |
| reduce_list | Reduce duplicate items in a list and preserve order. |
| flatten_dict | Flatten a nested dictionary to a flat one. |
| pairwise | Return an iterator of overlapping pairs taken from the input iterator. |
| permutations | Return successive r-length permutations of elements in the iterable. |
| product | Cartesian product of input iterables. |
| repeat | Make an iterator that returns object over and over again. |
| zip | Zip iterables into a single one. |
| zip_longest | Make an iterator that aggregates elements from each of the iterables. |
| natsort | Using the natsort package, sort a list naturally. |
| any | Check if at least one of the item in the sequence evaluates to true. |
| batch | A filter that batches items. It works pretty much like slice |
| first | Return the first item of a sequence. |
| groupby | Group a sequence of objects by an attribute using Python's |
| join | Return a string which is the concatenation of the strings in the |
| last | Return the last item of a sequence. |
| length | Return the number of items in a container. |
| reject | Filters a sequence of objects by applying a test to each object, |
| rejectattr | Filters a sequence of objects by applying a test to the specified |
| reverse | Reverse the object or return an iterator that iterates over it the other |
| select | Filters a sequence of objects by applying a test to each object, |
| selectattr | Filters a sequence of objects by applying a test to the specified |
| slice | Slice an iterator and return a list of lists containing |
| sort | Sort an iterable using Python's :func:sorted. |
| unique | Returns a list of unique items from the given iterable. |
markdown¶
| Name | Description |
|---|---|
| md_link | Create a markdown link. |
| autoref_link | Create a markdown autorefs-style link (used by MkDocs / MkDocStrings). |
| md_escape | Helper function to escape markup. |
| md_style | Apply styling to given markdown. |
| extract_header_section | Extract block with given header from markdown. |
| shift_header_levels | Shift the level of all headers of given text. |
misc¶
| Name | Description |
|---|---|
| add | Add a pre- or suffix to a value if the value is true-ish. |
| ternary | Value ? true_val : false_val. |
| match | A filter trying to imitate a python match-case statement. |
| import_module | Import a module. |
| hasattr | Return whether the object has an attribute with the given name. |
| partial | Create new function with partial application of given arguments / keywords. |
| load_file | Return the text-content of file at given path. |
| get_hash | Get a Md5 hash for given object. |
| check_output | Execute a system call and return its output as a string. |
| getenv | Get an environment variable, return None if it doesn't exist. |
| attr | Get an attribute of an object. foo|attr("bar") works like |
| default | If the value is undefined it will return the passed default value, |
| map | Applies a filter on a sequence of objects or looks up an attribute. |
| random | Return a random item from the sequence. |
number¶
| Name | Description |
|---|---|
| abs | Return the absolute value of the argument. |
| float | Convert the value into a floating point number. If the |
| min | Return the smallest item from the sequence. |
| max | Return the largest item from the sequence. |
| round | Round the number to a given precision. The first |
| sum | Returns the sum of a sequence of numbers plus the value of parameter |
path¶
| Name | Description |
|---|---|
| get_directory_tree | Create a DirectoryTree instance with the specified options. |
| expanduser | Expand ~ and ~user constructions. If user or $HOME is unknown, |
| expandvars | Expand shell variables of form $var and ${var}. Unknown variables |
| path_join | Join two or more pathname components, inserting '/' as needed. |
| fnmatch | Test whether FILENAME matches PATTERN. |
| fnmatchcase | Test whether FILENAME matches PATTERN, including case. |
| fnmatch_filter | Construct a list from those elements of the iterable NAMES that match PAT. |
| glob | Return a list of paths matching a pathname pattern. |
random¶
| Name | Description |
|---|---|
| choices | Return a k sized list of population elements chosen with replacement. |
| sample | Chooses k unique random elements from a population sequence. |
regex¶
| Name | Description |
|---|---|
| re_replace | Perform a re.sub returning a string. |
| re_findall | Perform re.findall and return the list of matches. |
| re_search | Perform re.search and return the list of matches or a backref. |
| re_escape | Escape all regular expressions special characters from STRING. |
serialize¶
| Name | Description |
|---|---|
| dump_json | Serialize obj to a JSON formatted str. |
| load_json | Deserialize s (a str, bytes or bytearray instance |
| load_toml | Parse TOML from a string. |
| serialize | Serialize given json-like object to given format. |
| deserialize | Serialize given json-like object to given format. |
| dig | Try to get data with given section path from a dict-list structure. |
| merge | Merge given data structures using mergers provided. |
| dictsort | Sort a dict and yield (key, value) pairs. Python dicts may not |
| items | Return an iterator over the (key, value) items of a mapping. |
| tojson | Serialize an object to a string of JSON, and mark it safe to |
text¶
| Name | Description |
|---|---|
| rstrip | Strip given chars from end of string. |
| lstrip | Strip given chars from beginning of string. |
| lower_camel_case | Convert given text to lower-camel-case. |
| snake_case | Convert given text to snake-case. |
| removesuffix | Return given suffix from text. |
| removeprefix | Return given prefix from text. |
| capitalize | Capitalize a value. The first character will be uppercase, all others |
| center | Centers the value in a field of a given width. |
| escape | Escape text using Markupsafe library. |
| forceescape | Enforce HTML escaping. This will probably double escape variables. |
| indent | Return a copy of the string with each line indented by 4 spaces. The |
| lower | Convert a value to lowercase. |
| replace | Return a copy of the value with all occurrences of a substring |
| safe | Mark the value as safe which means that in an environment with automatic |
| striptags | Strip SGML/XML tags and replace adjacent whitespace by one space. |
| title | Return a titlecased version of the value. I.e. words will start with |
| trim | Strip leading and trailing characters, by default whitespace. |
| truncate | Return a truncated copy of the string. The length is specified |
| upper | Convert a value to uppercase. |
| wordcount | Count the words in that string. |
| wordwrap | Wrap a string to the given width. Existing newlines are treated |
| ordinal | Converts an integer to its ordinal as a string. |
| intcomma | Converts an integer to a string containing commas every three digits. |
| intword | Converts a large integer to a friendly text representation. |
| apnumber | Converts an integer to Associated Press style. |
| fractional | Convert to fractional number. |
| scientific | Return number in string scientific notation z.wq x 10ⁿ. |
| clamp | Returns number with the specified format, clamped between floor and ceil. |
| naturalsize | Format a number of bytes like a human-readable filesize (e.g. 10 kB). |
time¶
| Name | Description |
|---|---|
| format_timestamp | Format Unix timestamp to date string. |
| naturaldate | Like naturalday, but append a year for dates more than ~five months away. |
| naturalday | Return a natural day. |
| naturaldelta | Return a natural representation of a timedelta or number of seconds. |
| naturaltime | Return a natural representation of a time in a resolution that makes sense. |
| precisedelta | Return a precise representation of a timedelta or number of seconds. |
type¶
| Name | Description |
|---|---|
| int | Convert the value into an integer. If the |
| list | Convert the value into a list. If it was a string the returned list |