<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: brickrecycler</title>
    <description>The latest articles on DEV Community by brickrecycler (@brickrecycler).</description>
    <link>https://dev.to/brickrecycler</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4226644%2Ff222e94f-6431-4939-a4a2-79ab46198234.webp</url>
      <title>DEV Community: brickrecycler</title>
      <link>https://dev.to/brickrecycler</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/brickrecycler"/>
    <language>en</language>
    <item>
      <title>Build a Simple LEGO Inventory Tracker with Python and CSV</title>
      <dc:creator>brickrecycler</dc:creator>
      <pubDate>Wed, 04 Nov 2026 15:55:57 +0000</pubDate>
      <link>https://dev.to/brickrecycler/build-a-simple-lego-inventory-tracker-with-python-and-csv-ko2</link>
      <guid>https://dev.to/brickrecycler/build-a-simple-lego-inventory-tracker-with-python-and-csv-ko2</guid>
      <description>&lt;p&gt;A mixed LEGO collection can be hard to sort. Some pieces get used all the time, some belong to sets you want to keep together, and others have been sitting in a bin for years. A small Python script can help you decide what to keep and what to donate.&lt;/p&gt;

&lt;p&gt;The trick is to track groups of pieces instead of counting every brick. One row can represent a bag, a bin, or a set.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create the inventory
&lt;/h2&gt;

&lt;p&gt;Save this as &lt;code&gt;lego_inventory.csv&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;group,container,decision
Loose bricks,Blue bin,keep
Space set,Clear bag,keep
Extra bricks,Small box,donate
Mixed pieces,Red bin,review
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;decision&lt;/code&gt; column tells the script what you plan to do with each group. Use &lt;code&gt;review&lt;/code&gt; when you need more time to decide.&lt;/p&gt;

&lt;h2&gt;
  
  
  Build the Python script
&lt;/h2&gt;

&lt;p&gt;Save this as &lt;code&gt;lego_inventory.py&lt;/code&gt; in the same folder:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;csv&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pathlib&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Path&lt;/span&gt;

&lt;span class="n"&gt;inventory_path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;__file__&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;with_name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;lego_inventory.csv&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;inventory_path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;encoding&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;utf-8&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;newline&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;inventory&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;csv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DictReader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;inventory&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;decision&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;lower&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;donate&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;group&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; (&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;container&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;)&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run it with &lt;code&gt;python lego_inventory.py&lt;/code&gt;. With the sample file, it prints &lt;code&gt;Extra bricks (Small box)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;csv.DictReader&lt;/code&gt; uses the header row as the field names. That lets you write &lt;code&gt;row["decision"]&lt;/code&gt; and still get the right value if you rearrange the columns.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use the list to pack your donation
&lt;/h2&gt;

&lt;p&gt;Once you’ve sorted your collection, run the script again to see which containers are ready to pack. If you’re in the U.S., &lt;a href="https://brickrecycler.com/" rel="noopener noreferrer"&gt;Brick Recycler&lt;/a&gt; accepts LEGO donations, including loose bricks and incomplete sets. You can find packing and shipping instructions on its website.&lt;/p&gt;

</description>
      <category>python</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
