# Can you access template functions from python with the \`inline\` plugin?

**URL:** <https://discourse.beets.io/t/can-you-access-template-functions-from-python-with-the-inline-plugin/753>\
**Category:** Help\
**Created:** [May 14, 2019, 4:20pm UTC](https://discourse.beets.io/t/can-you-access-template-functions-from-python-with-the-inline-plugin/753 "2019-05-14T16:20:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kergoth](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.beets.io/kergoth/32/240_2.png) [@kergoth](https://discourse.beets.io/u/kergoth)\
**Post date:** [May 14, 2019, 4:20pm UTC](https://discourse.beets.io/t/can-you-access-template-functions-from-python-with-the-inline-plugin/753/1 "2019-05-14T16:20:27Z")

</div>

I’m wondering if it’s possible to use template functions like `%aunique` from inline python (`inline` plugin) in a path format. Thanks!

-kergoth

---

<div class="post-metadata">

**Author:** ![adrian](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.beets.io/adrian/32/4_2.png) [@adrian](https://discourse.beets.io/u/adrian)\
**Post date:** [May 14, 2019, 5:11pm UTC](https://discourse.beets.io/t/can-you-access-template-functions-from-python-with-the-inline-plugin/753/2 "2019-05-14T17:11:31Z")

</div>

Not directly, unfortunately! But you might be able to invoke the underlying Python functions:

> <https://github.com/beetbox/beets/blob/909fd1eb272691d5cccaa0426db74871c770a8bb/beets/library.py#L1522>

---

<div class="post-metadata">

**Author:** ![kergoth](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.beets.io/kergoth/32/240_2.png) [@kergoth](https://discourse.beets.io/u/kergoth)\
**Post date:** [May 15, 2019, 4:47pm UTC](https://discourse.beets.io/t/can-you-access-template-functions-from-python-with-the-inline-plugin/753/3 "2019-05-15T16:47:12Z")

</div>

I don’t think that’s a viable option, since `tmpl_aunique` isn’t a staticmethod, so requires the item and lib to construct the object, which I doubt you can do from inside an inline python block. Is that correct, or is there a way to get to the library object from `album_fields`?

---

<div class="post-metadata">

**Author:** ![adrian](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.beets.io/adrian/32/4_2.png) [@adrian](https://discourse.beets.io/u/adrian)\
**Post date:** [May 15, 2019, 8:03pm UTC](https://discourse.beets.io/t/can-you-access-template-functions-from-python-with-the-inline-plugin/753/4 "2019-05-15T20:03:38Z")

</div>

Indeed—it’s certainly not easily done, but perhaps with enough hacking you can construct your own `Library` object, linked to the appropriate database, to obtain the object you need.

---

<div class="post-metadata">

**Author:** ![ctrueden](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.beets.io/ctrueden/32/475_2.png) [@ctrueden](https://discourse.beets.io/u/ctrueden)\
**Post date:** [October 11, 2020, 6:17pm UTC](https://discourse.beets.io/t/can-you-access-template-functions-from-python-with-the-inline-plugin/753/5 "2020-10-11T18:17:42Z")

</div>

This question came up again in another topic, with a solution posted there:

> [@Using template functions with the inline plugin](https://discourse.beets.io/t/using-template-functions-with-the-inline-plugin/1267/3):
>
> Changed my code to initial: | import beets.plugins the\_func = beets.plugins.template\_funcs()['the'] the\_artist = the\_func(albumartist\_sort or artist\_sort or albumartist or artist or '\_') return the\_artist[0].upper() And this works like a charm. Thanks!
