# Python 101 - delete library

**URL:** <https://forum.logik.tv/t/python-101-delete-library/3977>\
**Category:** Python\
**Tags:** media-panel\
**Created:** [October 7, 2021, 3:19pm UTC](https://forum.logik.tv/t/python-101-delete-library/3977 "2021-10-07T15:19:12Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![cicero](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@cicero](https://forum.logik.tv/u/cicero)\
**Post date:** [October 7, 2021, 3:19pm UTC](https://forum.logik.tv/t/python-101-delete-library/3977/1 "2021-10-07T15:19:12Z")

</div>

Hi all,

Flame user of 10+ yrs but new to the forum and it’s great what you’re doing here!

Total newbie with python scripts and I’m just starting with some real basics, like creating a bespoke set of libraries and subfolders in a fresh project. I think I’ve nailed it (thanks to @andymilkis and @fredwarren for Logik Live Ep #07)… apart from deleting the automatically-generated Default Library. Any pointers please?

Thanks

---

<div class="post-metadata">

**Author:** ![andymilkis](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.logik.tv/andymilkis/32/11067_2.png) [@andymilkis](https://forum.logik.tv/u/andymilkis)\
**Post date:** [October 7, 2021, 3:23pm UTC](https://forum.logik.tv/t/python-101-delete-library/3977/2 "2021-10-07T15:23:18Z")

</div>

Welcome Franz! Glad you enjoyed Ep 7! It seems like forever ago…this Sunday is #65 🙂

Here’s how I solved it:

At the top of the script I defined the existing default library that is created with a new project:

default\_library = ws.libraries[0]

Then at the end of my script I have this to remove the default library:

if “Default Library” in str(default\_library.name):  
flame.delete(default\_library)

HTH!

Andy

---

<div class="post-metadata">

**Author:** ![claussteinmassl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.logik.tv/claussteinmassl/32/1922_2.png) [@claussteinmassl](https://forum.logik.tv/u/claussteinmassl)\
**Post date:** [October 7, 2021, 3:34pm UTC](https://forum.logik.tv/t/python-101-delete-library/3977/3 "2021-10-07T15:34:15Z")

</div>

The default library could probably be at any index. I would either iterate over all libraries to find it or use the build in function from the flame module to find it.

Find by iterating over all libs:

```auto
for lib in flame.project.current_project.current_workspace.libraries:
    if lib.name.get_value() == "Default Library":
        flame.delete(lib)

```

Find by using the flame module’s function:

```auto
for lib in flame.find_by_name("Default Library"):
    # make sure we are really dealing with a lib and not any other item that is just called "Default Library"
    if isinstance(lib, flame.PyLibrary):
        flame.delete(lib)

```

Find by name reference:  
[https://help.autodesk.com/view/FLAME/2022/ENU/?guid=Flame\_API\_Python\_API\_autodesk\_flame\_python\_api\_html#-find\_by\_name](https://help.autodesk.com/view/FLAME/2022/ENU/?guid=Flame_API_Python_API_autodesk_flame_python_api_html#-find_by_name)

---

<div class="post-metadata">

**Author:** ![claussteinmassl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.logik.tv/claussteinmassl/32/1922_2.png) [@claussteinmassl](https://forum.logik.tv/u/claussteinmassl)\
**Post date:** [October 7, 2021, 3:40pm UTC](https://forum.logik.tv/t/python-101-delete-library/3977/4 "2021-10-07T15:40:53Z")

</div>

> [@andymilkis](#):
>
> if “Default Library” in str(default\_library.name):

By using default\_library.name.get\_value() you will directly get a string instead of a flame.PyAttribute and don’t need to do a conversion. 🙂

---

<div class="post-metadata">

**Author:** ![cicero](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@cicero](https://forum.logik.tv/u/cicero)\
**Post date:** [October 7, 2021, 3:49pm UTC](https://forum.logik.tv/t/python-101-delete-library/3977/5 "2021-10-07T15:49:11Z")

</div>

Thanks both. Out of the 3 options I could only get the iteration over all libs working, but that’s done it!  
When I get more time I’ll work out how to make the other options work. It’s pretty heavy going when you’re this new to python.  
Thanks again

---

<div class="post-metadata">

**Author:** ![claussteinmassl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.logik.tv/claussteinmassl/32/1922_2.png) [@claussteinmassl](https://forum.logik.tv/u/claussteinmassl)\
**Post date:** [October 7, 2021, 3:55pm UTC](https://forum.logik.tv/t/python-101-delete-library/3977/6 "2021-10-07T15:55:58Z")

</div>

Let us know what errors you get and we can help. 🙂

---

<div class="post-metadata">

**Author:** ![Jason\_Chambers](https://avatars.discourse-cdn.com/v4/letter/j/ecb155/32.png) [@Jason\_Chambers](https://forum.logik.tv/u/Jason_Chambers)\
**Post date:** [October 8, 2021, 11:17am UTC](https://forum.logik.tv/t/python-101-delete-library/3977/7 "2021-10-08T11:17:44Z")

</div>

Hi all,  
I have a similar request, I’m hoping to get the library name that contains the sequence I’m exporting to use in the file path.  
Tried all variations on current library but no joy.  
Any ideas?

---

<div class="post-metadata">

**Author:** ![claussteinmassl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.logik.tv/claussteinmassl/32/1922_2.png) [@claussteinmassl](https://forum.logik.tv/u/claussteinmassl)\
**Post date:** [October 8, 2021, 12:00pm UTC](https://forum.logik.tv/t/python-101-delete-library/3977/8 "2021-10-08T12:00:26Z")

</div>

Hey Jason,

PySequences do have a parent attribute, but I think this will only help you if the selected clip is in the library:  
[https://help.autodesk.com/view/FLAME/2022/ENU/?guid=Flame\_API\_Python\_API\_autodesk\_flame\_python\_api\_html#PySequence](https://help.autodesk.com/view/FLAME/2022/ENU/?guid=Flame_API_Python_API_autodesk_flame_python_api_html#PySequence)

If the sequence is on your current desk and you want to find the library where it has also been saved you probably need to crawl all libraries to find the sequence. Have a look at this code snippet which shows you how to collect clips from libraries with an unknown level of subfolders:

> [@Mimic os.walk](https://forum.logik.tv/t/mimic-os-walk/3631/2):
>
> Recursion is your friend! slight_smile By calling the function from itself again you can traverse through an unknown level of subfolders. Here is a little example to build a list of all clips. I’ve modified some names slightly to stick to some Autodesk terminology (e.g. clips instead of entries etc.) to make things more understandable. Hope this helps. slight_smile import flame clips = [] def build\_clip\_list(current\_folder): """recursive search for entries""" global clips fo…

Instead of just adding every clip (clips.append(clip)) you would add a check if the clip name equals your clip name.

---

<div class="post-metadata">

**Author:** ![Jason\_Chambers](https://avatars.discourse-cdn.com/v4/letter/j/ecb155/32.png) [@Jason\_Chambers](https://forum.logik.tv/u/Jason_Chambers)\
**Post date:** [October 8, 2021, 12:26pm UTC](https://forum.logik.tv/t/python-101-delete-library/3977/9 "2021-10-08T12:26:29Z")

</div>

Thanks for you help Claus,  
The clip will always be in a library.  
Had a look at the link and can return lots of sequence info but don’t see any way to get which library its saved in.

---

<div class="post-metadata">

**Author:** ![claussteinmassl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.logik.tv/claussteinmassl/32/1922_2.png) [@claussteinmassl](https://forum.logik.tv/u/claussteinmassl)\
**Post date:** [October 8, 2021, 12:35pm UTC](https://forum.logik.tv/t/python-101-delete-library/3977/10 "2021-10-08T12:35:08Z")

</div>

Did you try to use the parent attribute as mentioned before?

Select your sequence in the media panel, run this and you will see the libraries name printed:

```auto
for item in flame.media_panel.selected_entries:
    print item.parent.name.get_value()

```

---

<div class="post-metadata">

**Author:** ![Jason\_Chambers](https://avatars.discourse-cdn.com/v4/letter/j/ecb155/32.png) [@Jason\_Chambers](https://forum.logik.tv/u/Jason_Chambers)\
**Post date:** [October 8, 2021, 12:38pm UTC](https://forum.logik.tv/t/python-101-delete-library/3977/11 "2021-10-08T12:38:35Z")

</div>

> [@claussteinmassl](#):
>
> `item.parent.name.get_value()`

Amazing, thanks so much

---

<div class="post-metadata">

**Author:** ![claussteinmassl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.logik.tv/claussteinmassl/32/1922_2.png) [@claussteinmassl](https://forum.logik.tv/u/claussteinmassl)\
**Post date:** [October 8, 2021, 12:39pm UTC](https://forum.logik.tv/t/python-101-delete-library/3977/12 "2021-10-08T12:39:26Z")

</div>

You’re welcome! 🙂

---

<div class="post-metadata">

**Author:** ![andymilkis](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.logik.tv/andymilkis/32/11067_2.png) [@andymilkis](https://forum.logik.tv/u/andymilkis)\
**Post date:** [October 10, 2021, 2:32am UTC](https://forum.logik.tv/t/python-101-delete-library/3977/13 "2021-10-10T02:32:46Z")

</div>

Thank you!!

---

<div class="post-metadata">

**Author:** ![kily](https://avatars.discourse-cdn.com/v4/letter/k/a88e4f/32.png) [@kily](https://forum.logik.tv/u/kily)\
**Post date:** [June 14, 2023, 3:31pm UTC](https://forum.logik.tv/t/python-101-delete-library/3977/14 "2023-06-14T15:31:18Z")

</div>

Hi! First of all , sorry for bump this.

Coming back to first question, I’m trying to use _find\_by\_name_ method and I would need return the name of founded items. According with the succint help, it seems that this function returns a list. Taking the second example, I tried to print the list with something like:

```auto
for lib in flame.find_by_name("Default Library"):
    if isinstance(lib, flame.PyLibrary):
        print(lib[:])

```

but it does not work.

Also, I wonder if _find\_by\_name_ method can use \* or so, to perform basic searchs, to find, for example, all libraries started by “tmp”

---

<div class="post-metadata">

**Author:** ![MikeV](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.logik.tv/mikev/32/399_2.png) [@MikeV](https://forum.logik.tv/u/MikeV)\
**Post date:** [June 14, 2023, 3:51pm UTC](https://forum.logik.tv/t/python-101-delete-library/3977/15 "2023-06-14T15:51:45Z")

</div>

This should work:

```auto
for lib in flame.find_by_name("Default Library"):
    if isinstance(lib, flame.PyLibrary):
        print(lib)

```

---

<div class="post-metadata">

**Author:** ![kily](https://avatars.discourse-cdn.com/v4/letter/k/a88e4f/32.png) [@kily](https://forum.logik.tv/u/kily)\
**Post date:** [June 14, 2023, 4:20pm UTC](https://forum.logik.tv/t/python-101-delete-library/3977/16 "2023-06-14T16:20:52Z")

</div>

It was my first option. Using

`print(lib)`

Console returns:

`<flame.PyLibrary object at 0x7f4477e66432>`

Trying to figure out the kind of object returned by find\_by\_name, using

`print(type(lib))`

` <class ´flame.PyLibrary´>`

---

<div class="post-metadata">

**Author:** ![MikeV](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.logik.tv/mikev/32/399_2.png) [@MikeV](https://forum.logik.tv/u/MikeV)\
**Post date:** [June 14, 2023, 5:02pm UTC](https://forum.logik.tv/t/python-101-delete-library/3977/17 "2023-06-14T17:02:58Z")

</div>

What are you trying to do?

---

<div class="post-metadata">

**Author:** ![kily](https://avatars.discourse-cdn.com/v4/letter/k/a88e4f/32.png) [@kily](https://forum.logik.tv/u/kily)\
**Post date:** [June 14, 2023, 5:19pm UTC](https://forum.logik.tv/t/python-101-delete-library/3977/18 "2023-06-14T17:19:46Z")

</div>

As part of a script project, I’m using a temp library. I would like delete it after finishing the script. So I want to check if some temp libraries exist, and delete it, printing it in console with something like ´temp library deleted´ . And beyond, also check if temp 1 , temp 2 exist, and delete all of them.

---

<div class="post-metadata">

**Author:** ![MikeV](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.logik.tv/mikev/32/399_2.png) [@MikeV](https://forum.logik.tv/u/MikeV)\
**Post date:** [June 14, 2023, 5:34pm UTC](https://forum.logik.tv/t/python-101-delete-library/3977/19 "2023-06-14T17:34:35Z")

</div>

Ah… you could do something like this:

```auto
for lib in flame.project.current_project.current_workspace.libraries:
    if lib.name in ['temp 1', 'temp 2']:
        flame.delete(lib)
        print('Temp library deleted')

```

---

<div class="post-metadata">

**Author:** ![kily](https://avatars.discourse-cdn.com/v4/letter/k/a88e4f/32.png) [@kily](https://forum.logik.tv/u/kily)\
**Post date:** [June 14, 2023, 6:26pm UTC](https://forum.logik.tv/t/python-101-delete-library/3977/20 "2023-06-14T18:26:20Z")

</div>

Sorry, I did not explain well. I meant that I wanted to print on the screen the actual names of the libraries founded.

But your answer gave me the right and simply answer. The right object is lib.name.

So it would be:

```auto
for lib in flame.find_by_name("temp"):
    if isinstance(lib, flame.PyLibrary):
        print(lib.name, ' library deleted')

```

… and it works.

I know it doesn’t make sense if I am looking for a specific name. But I was thinking if I could find more variations of that name (temp 1 , temp2 , temp whatever … and so on) with some procedural way and display the precise information about what was founded and deleted.

I don’t think _find\_by\_name_ supports things like ´’temp\*’ . I suppose I could try an if statement like you propose but with some kind of regular expression to make it more procedural.

Needless to say, I’m a complete noob with this.
