<?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: Mukul Dutt</title>
    <description>The latest articles on DEV Community by Mukul Dutt (@paper_andbeyond).</description>
    <link>https://dev.to/paper_andbeyond</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4065105%2F0a8fcf42-20a6-4afa-861c-a5bf30fb6ceb.png</url>
      <title>DEV Community: Mukul Dutt</title>
      <link>https://dev.to/paper_andbeyond</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/paper_andbeyond"/>
    <language>en</language>
    <item>
      <title>Build a politician stock tracker in Python</title>
      <dc:creator>Mukul Dutt</dc:creator>
      <pubDate>Thu, 26 Nov 2026 17:17:28 +0000</pubDate>
      <link>https://dev.to/paper_andbeyond/build-a-politician-stock-tracker-in-python-51k3</link>
      <guid>https://dev.to/paper_andbeyond/build-a-politician-stock-tracker-in-python-51k3</guid>
      <description>&lt;p&gt;&lt;em&gt;By Mukul Dutt, founder of &lt;a href="https://edgrapi.com" rel="noopener noreferrer"&gt;Edgrapi&lt;/a&gt; (an API for SEC and US government data). Last updated November 2026.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Who in Congress traded NVDA last month, and did any NVDA insiders buy?&lt;/p&gt;

&lt;p&gt;You can answer both with free government data and about 150 lines of Python. A politician stock tracker needs two sources, House periodic transaction reports (PTRs) from the House Clerk for members of Congress and SEC Form 4 filings from EDGAR for corporate insiders. Both are free, neither needs a key, and both have parsing traps that quietly drop trades if you don't handle them.&lt;/p&gt;

&lt;p&gt;I built this pipeline for my own product, so this is the version that survived real data. Everything below ran on November 25, 2026, and every output block is what came back that day.&lt;/p&gt;

&lt;p&gt;You need Python 3, &lt;code&gt;requests&lt;/code&gt; and &lt;code&gt;pypdf&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip install requests pypdf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What does a politician stock tracker need?
&lt;/h2&gt;

&lt;p&gt;A politician stock tracker needs the House Clerk's yearly disclosure index, the PTR PDFs it points to, and a parser for the trade rows inside them. An insider trading tracker needs SEC Form 4 XML from EDGAR. The two sources have different formats, different deadlines and different failure modes, so treat them as two pipelines that share one output table.&lt;/p&gt;

&lt;p&gt;Here's how the two compare, based on my runs on NVDA:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Insider trades (SEC Form 4)&lt;/th&gt;
&lt;th&gt;Congress trades (House PTRs)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Where&lt;/td&gt;
&lt;td&gt;EDGAR, &lt;code&gt;data.sec.gov&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;House Clerk, &lt;code&gt;disclosures-clerk.house.gov&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Format&lt;/td&gt;
&lt;td&gt;Clean XML&lt;/td&gt;
&lt;td&gt;PDF, typed or scanned&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Deadline&lt;/td&gt;
&lt;td&gt;2nd business day after the trade&lt;/td&gt;
&lt;td&gt;30 days from notice or 45 days from the trade&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Amounts&lt;/td&gt;
&lt;td&gt;Exact shares and price&lt;/td&gt;
&lt;td&gt;Dollar ranges only&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Find by ticker&lt;/td&gt;
&lt;td&gt;Yes, via the company's CIK&lt;/td&gt;
&lt;td&gt;No, you read every PDF&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;My NVDA run&lt;/td&gt;
&lt;td&gt;40 filings in 24 seconds&lt;/td&gt;
&lt;td&gt;150 PDFs in 95 seconds&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The Senate is a separate site with its own problems, which I'll get to later.&lt;/p&gt;

&lt;h2&gt;
  
  
  How do I pull insider trades from SEC EDGAR in Python?
&lt;/h2&gt;

&lt;p&gt;EDGAR's APIs are free and keyless, but the SEC asks every script to send a User-Agent with a real name and email, and its &lt;a href="https://www.sec.gov/search-filings/edgar-search-assistance/accessing-edgar-data" rel="noopener noreferrer"&gt;fair access page&lt;/a&gt; caps you at 10 requests per second. Skip the header and you get 403 errors that look like an outage. The route is three hops, ticker to CIK, CIK to recent filings, filing to Form 4 XML.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;primaryDocument&lt;/code&gt; field points at the rendered HTML version, inside an &lt;code&gt;xslF345X05/&lt;/code&gt; folder. Strip that folder and you get the raw XML.&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="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;xml&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;etree&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ElementTree&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="no"&gt;ET&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;

&lt;span class="no"&gt;HEADERS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"User-Agent"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Jane Dev jane@example.com"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;  &lt;span class="c1"&gt;# SEC wants a real name + email here&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;cik_for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ticker&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"https://www.sec.gov/files/company_tickers.json"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="no"&gt;HEADERS&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="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;values&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&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="s2"&gt;"ticker"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;ticker&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;upper&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"cik_str"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"unknown ticker {ticker}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;recent_form4s&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cik&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;limit&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"https://data.sec.gov/submissions/CIK{cik:010d}.json"&lt;/span&gt;
    &lt;span class="n"&gt;recent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="no"&gt;HEADERS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"filings"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"recent"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;out&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&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;form&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;acc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;filed&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;zip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;recent&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"form"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;recent&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"accessionNumber"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                                     &lt;span class="n"&gt;recent&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"primaryDocument"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;recent&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"filingDate"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&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;form&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"4"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"4/A"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="c1"&gt;# primaryDocument points at the rendered HTML (xslF345X05/...); drop the&lt;/span&gt;
            &lt;span class="c1"&gt;# xsl folder to get the raw XML&lt;/span&gt;
            &lt;span class="n"&gt;raw&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"/"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
            &lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;form&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;filed&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"https://www.sec.gov/Archives/edgar/data/{cik}/"&lt;/span&gt;
                                     &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{acc.replace('-', '')}/{raw}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;limit&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;break&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;out&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The submissions API only holds the most recent 1,000 or so filings in its &lt;code&gt;recent&lt;/code&gt; block. For deeper history you page through the extra files listed under &lt;code&gt;filings.files&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What does transaction code P mean on a Form 4?
&lt;/h2&gt;

&lt;p&gt;Code P is an open-market or private purchase, the only Form 4 code where an insider bought stock with their own money. The &lt;a href="https://www.sec.gov/files/form4.pdf" rel="noopener noreferrer"&gt;SEC's Form 4 instructions&lt;/a&gt; list S for sales, A for grants, M for option exercises, G for gifts and F for shares withheld to pay tax. Form 4 is due before the end of the second business day after the trade, so this data is nearly current.&lt;/p&gt;

&lt;p&gt;On a big-cap name like NVDA, almost every row is S, A, M or G.&lt;/p&gt;

&lt;p&gt;Sales need one more check. Since the SEC's &lt;a href="https://www.sec.gov/rules-regulations/2022/12/insider-trading-arrangements-related-disclosures" rel="noopener noreferrer"&gt;December 2022 rule change&lt;/a&gt;, Form 4 has a checkbox that flags trades made under a Rule 10b5-1 plan. Those trades were scheduled months earlier, so they say little about what the insider thinks today.&lt;/p&gt;

&lt;p&gt;In the XML that checkbox is the &lt;code&gt;aff10b5One&lt;/code&gt; element. Older filings mention the plan only in a footnote, so I check both.&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="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;parse_form4&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;root&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;ET&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fromstring&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="no"&gt;HEADERS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;owner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;root&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findtext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"reportingOwner/reportingOwnerId/rptOwnerName"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="c1"&gt;# filing-level checkbox, added to Form 4 in April 2023&lt;/span&gt;
    &lt;span class="n"&gt;plan_box&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;root&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findtext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"aff10b5One"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&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="p"&gt;)&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="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"true"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;plan_notes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"id"&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;fn&lt;/span&gt; &lt;span class="nf"&gt;in&lt;/span&gt; &lt;span class="n"&gt;root&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;iter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"footnote"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="s2"&gt;"10b5-1"&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;itertext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;rows&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&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;tx&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;root&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;iter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"nonDerivativeTransaction"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;refs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"id"&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;f&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;tx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;iter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"footnoteId"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="n"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="s2"&gt;"owner"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s2"&gt;"date"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;tx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findtext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"transactionDate/value"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s2"&gt;"code"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;tx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findtext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"transactionCoding/transactionCode"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s2"&gt;"shares"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findtext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"transactionAmounts/transactionShares/value"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s2"&gt;"price"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findtext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"transactionAmounts/transactionPricePerShare/value"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s2"&gt;"plan"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;plan_box&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;refs&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;plan_notes&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;rows&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How do I stop Form 4 amendments from double-counting trades?
&lt;/h2&gt;

&lt;p&gt;Group transactions by owner and trade date, and let the most recently filed document win. A Form 4/A restates an earlier filing, so counting both doubles the trade, and the XML has no clean pointer from the amendment back to the original. Keying on owner plus date is the practical fix, and in my NVDA run it collapsed one amendment correctly.&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="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"__main__"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;cik&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;cik_for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"NVDA"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;filings&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;recent_form4s&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cik&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="c1"&gt;# A 4/A restates an earlier Form 4. Group rows by (owner, trade date) and let the&lt;/span&gt;
    &lt;span class="c1"&gt;# most recently filed document win, so an amendment replaces what it corrects.&lt;/span&gt;
    &lt;span class="n"&gt;latest&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&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;form&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;filed&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;filings&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.15&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# stay well under SEC's 10 requests/second&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;parse_form4&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"owner"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"date"&lt;/span&gt;&lt;span class="p"&gt;]&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;key&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;latest&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;filed&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;latest&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;latest&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;filed&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&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;latest&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;latest&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;rows&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;filed&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;t&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;filed&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ts&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;latest&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;values&lt;/span&gt;&lt;span class="p"&gt;(&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;t&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;ts&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;buys&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;rows&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"code"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"P"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;sells&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;rows&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"code"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"S"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{len(filings)} filings, {len(rows)} transactions after amendments"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"open-market sales: {len(sells)} ({sum(r[2]['plan'] for r in sells)} under a 10b5-1 plan)"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"open-market buys (code P): {len(buys)}"&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;filed&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;buys&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;filed&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"owner"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"shares"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"@"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"price"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output on NVDA, about 24 seconds:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;40 filings, 76 transactions after amendments
open-market sales: 44 (22 under a 10b5-1 plan)
open-market buys (code P): 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Zero buys is the real answer for NVDA. Its insiders are paid in stock and sell on schedules.&lt;/p&gt;

&lt;p&gt;The useful number is the 22 planned sales, half of all sales. A naive insider trading tracker would flag those loudest, and they carry the least information. Run the same script on a small-cap and you'll usually see some P rows.&lt;/p&gt;

&lt;h2&gt;
  
  
  How do I track congressional stock trades for free?
&lt;/h2&gt;

&lt;p&gt;Download the House Clerk's yearly index, keep the rows with filing type P, and read each PTR PDF for trade rows. Under the rules on the &lt;a href="https://ethics.house.gov/financial-disclosure" rel="noopener noreferrer"&gt;House Ethics financial disclosure page&lt;/a&gt;, members report transactions over $1,000 within 30 days of learning about them or 45 days of the trade, whichever comes first. The index has no tickers, so finding one stock means reading every PDF.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://disclosures-clerk.house.gov/FinancialDisclosure" rel="noopener noreferrer"&gt;House Clerk&lt;/a&gt; publishes the index as a zip, &lt;code&gt;2026FD.zip&lt;/code&gt;, with a tab-separated file inside. As of November 25, 2026, it listed 481 PTRs filed this year.&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="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;io&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;zipfile&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pypdf&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;PdfReader&lt;/span&gt;

&lt;span class="no"&gt;HEADERS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"User-Agent"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Jane Dev jane@example.com"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="no"&gt;YEAR&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2026&lt;/span&gt;
&lt;span class="no"&gt;BASE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"https://disclosures-clerk.house.gov/public_disc"&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;ptr_index&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="s2"&gt;"""Every periodic transaction report (FilingType P) filed this year, newest first."""&lt;/span&gt;
    &lt;span class="n"&gt;z&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;zipfile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ZipFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;io&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;BytesIO&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{BASE}/financial-pdfs/{year}FD.zip"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="no"&gt;HEADERS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;lines&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{year}FD.txt"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"utf-8"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"replace"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;splitlines&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;out&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&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;line&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;lines&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"\t"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"P"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"/"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"member"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{f[2]} {f[1]}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"district"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                        &lt;span class="s2"&gt;"filed"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{y}-{int(m):02d}-{int(d):02d}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"doc_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&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="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;sorted&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"filed"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;reverse&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pad the dates before sorting. The index writes dates like &lt;code&gt;9/4/2026&lt;/code&gt;, and my first run sorted September above November as strings, so my "newest 150" was really a late-summer sample until I caught it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why does my congressional trade parser miss trades?
&lt;/h2&gt;

&lt;p&gt;Most missed trades come from scanned PDFs with no text layer, a regex that expects a clean &lt;code&gt;$low - $high&lt;/code&gt; range, and index entries whose PDF isn't posted yet. In my run, 20 of the newest 150 PTRs were scans, about 13%, and they returned nothing. The top amount bracket reads "Over $50,000,000" with no upper bound, so a strict regex silently drops the largest trades.&lt;/p&gt;

&lt;p&gt;Every typed PTR row carries the ticker in parentheses, an asset-type tag, P, S or E, two dates and a dollar range.&lt;/p&gt;

&lt;p&gt;The text extraction also jams the transaction date and notification date together with no space. Partial sales print as &lt;code&gt;S (partial)&lt;/code&gt;. My first parser missed both.&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="c1"&gt;# "(NVDA) [ST]" then type, trade date, notification date, amount range.&lt;/span&gt;
&lt;span class="c1"&gt;# The PDF text layer often runs the two dates together with no space.&lt;/span&gt;
&lt;span class="no"&gt;ROW&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;compile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="s2"&gt;"\(([A-Z.]{1,6})\)\s*\[[A-Z]{2}\]\s*([PSE])(?:\s*\(partial\))?\s+"&lt;/span&gt;
                 &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="s2"&gt;"(\d{2}/\d{2}/\d{4})\s*(\d{2}/\d{2}/\d{4})\s*(?:Over\s*)?\$([\d,]+)"&lt;/span&gt;
                 &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="s2"&gt;"(?:\s*-\s*\$([\d,]+))?"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;trades_in&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;doc_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;pdf&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{BASE}/ptr-pdfs/{year}/{doc_id}.pdf"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="no"&gt;HEADERS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;pdf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startswith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="s2"&gt;"%PDF"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;   &lt;span class="c1"&gt;# listed in the index, PDF not posted yet&lt;/span&gt;
    &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"\n"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;extract_text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nc"&gt;PdfReader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;io&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;BytesIO&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pdf&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pages&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="c1"&gt;# one trade split across sub-accounts is printed once per account&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kt"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fromkeys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;ROW&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findall&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&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="p"&gt;)&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;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"__main__"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;ticker&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;scan&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"NVDA"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;150&lt;/span&gt;
    &lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;ptr_index&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;YEAR&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{len(index)} PTRs filed in {YEAR}; scanning the newest {scan}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;unreadable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;missing&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;scan&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;has_text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;trades_in&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"doc_id"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;YEAR&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;missing&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;has_text&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;
        &lt;span class="n"&gt;unreadable&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;has_text&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="kc"&gt;False&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;tk&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;kind&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;traded&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;lo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hi&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;rows&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;tk&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;ticker&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;side&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"P"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"buy"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"S"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"sell"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"E"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"exchange"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;kind&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
                &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"filed"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"member"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"district"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;side&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;traded&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                      &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"${lo}-${hi or '+'}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{BASE}/ptr-pdfs/{YEAR}/{f['doc_id']}.pdf"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{missing} not posted yet, {unreadable} with no text layer (scanned)"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output, about 95 seconds for 150 PDFs (trimmed):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;481 PTRs filed in 2026; scanning the newest 150
2026-11-18 Michael Rulli OH06 sell 10/28/2026 $1,001-$15,000 .../20036855.pdf
2026-11-05 Maria Elvira Salazar FL27 buy 10/23/2026 $1,001-$15,000 .../20035778.pdf
2026-10-27 Pete Sessions TX17 sell 10/02/2026 $15,001-$50,000 .../20035563.pdf
2026-10-22 Cleo Fields LA06 buy 10/01/2026 $1,001-$15,000 .../20035669.pdf
...
1 not posted yet, 20 with no text layer (scanned)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The one unposted PDF crashed &lt;code&gt;pypdf&lt;/code&gt; on my first run. The Clerk's server answered with a 404 HTML page, &lt;code&gt;requests&lt;/code&gt; doesn't raise on a 404 by default, and the &lt;code&gt;%PDF&lt;/code&gt; header check is what fixed it.&lt;/p&gt;

&lt;p&gt;Dates are loose too. One PTR filed November 23 lists an NVDA trade dated April 29, well past the 45-day window, and the PDF won't tell you whether that's a late filing or a typo.&lt;/p&gt;

&lt;h2&gt;
  
  
  What about Senate stock trades?
&lt;/h2&gt;

&lt;p&gt;Senate trades are filed on the Senate's own eFD site, efdsearch.senate.gov, not with the House Clerk. The site puts searches behind an agreement page and a session, and it has been refusing scripted requests, so a free Senate tracker means browser automation or a paid data source. Every script in this article is House only, and so is the hosted option below.&lt;/p&gt;

&lt;h2&gt;
  
  
  Which trades should a politician stock tracker alert on?
&lt;/h2&gt;

&lt;p&gt;Alert on discretionary buys and ignore most of the rest. For insiders, that means code P purchases, especially when two or more insiders buy within a few weeks. For Congress, it means purchases in the larger dollar ranges and trades in sectors a member's committee oversees. Grants, option exercises, tax withholding and 10b5-1 plan sales are noise for a buy signal.&lt;/p&gt;

&lt;p&gt;This is the filter I use.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Drop everything except codes P and S. On NVDA that left 44 of 76 transactions, all of them sales.&lt;/li&gt;
&lt;li&gt;Flag 10b5-1 sales separately instead of alerting on them. They were 22 of NVDA's 44 sales.&lt;/li&gt;
&lt;li&gt;Keep code P buys, and rank clusters of several insiders above single buys.&lt;/li&gt;
&lt;li&gt;For Congress, skip the smallest bracket, $1,001-$15,000, unless the member trades the stock repeatedly. A trade there can be as small as $1,001.&lt;/li&gt;
&lt;li&gt;Sort congressional alerts by filing date, not trade date. The trade date tells you when it happened, but the filing date is when you could have known.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If a backtest enters on the trade date, it assumes you knew about a trade weeks before the public did. Every result built that way looks better than anything you could have traded.&lt;/p&gt;

&lt;p&gt;Check whose account a congressional trade sits in, too. PTRs mark spouse and joint accounts, and a lot of headline trades turn out to be a spouse's managed account rather than the member's own decision.&lt;/p&gt;

&lt;h2&gt;
  
  
  Free scripts or a hosted API: which should you use?
&lt;/h2&gt;

&lt;p&gt;Use the free scripts if you track one or two tickers a week. Use a hosted API if you need many tickers, fast answers, or no PDF parsing at all. The House scan above downloads 150 PDFs to answer one ticker, so a real tracker runs it as a background job with a database behind it.&lt;/p&gt;

&lt;p&gt;That background job is what Edgrapi is. It's my product, so weigh this section accordingly.&lt;/p&gt;

&lt;p&gt;It keeps House PTRs parsed in a table as they're posted, parses and caches Form 4s per ticker, and the same NVDA question becomes two requests:&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="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;

&lt;span class="no"&gt;API&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"https://api.edgrapi.com/v1"&lt;/span&gt;
&lt;span class="no"&gt;HEADERS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"X-API-Key"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"EDGRAPI_KEY"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;ins&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{API}/insider/NVDA"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"limit"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="no"&gt;HEADERS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&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;f&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;ins&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"filings"&lt;/span&gt;&lt;span class="p"&gt;]&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;t&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"transactions"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&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;t&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"code"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"P"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"insider buy"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"filed"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"owner"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"value"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"url"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;cong&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{API}/congress/NVDA"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="no"&gt;HEADERS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&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;t&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;cong&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"trades"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"action"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"transaction_date"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"member"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"amount_low"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"amount_high"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"disclosure_url"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each congressional trade links to the original House PDF, so you can still cite the source. The NVDA congress trades Edgrapi had on file the day I wrote this match what the free scan found.&lt;/p&gt;

&lt;p&gt;The insider call costs 5 credits and the congress call 2. The free tier is 50 credits with no card, enough for about seven tickers, and Starter is $10 a month for 10,000 credits.&lt;/p&gt;

&lt;p&gt;The data limits carry over. Coverage is House only, trades can show up 45 days or more after they happen, amounts stay as ranges, and scanned PTRs are missing there too because it reads the same text layer.&lt;/p&gt;

&lt;p&gt;Two more gaps. &lt;code&gt;/v1/insider&lt;/code&gt; returns original Form 4s, so keep the 4/A handling from the script if amendments matter to you. And its &lt;code&gt;plan_10b5_1&lt;/code&gt; flag is read from footnotes, not the &lt;code&gt;aff10b5One&lt;/code&gt; checkbox. On these 40 NVDA filings the two agreed on all 22 planned sales, but read the checkbox yourself if you need it exactly.&lt;/p&gt;

&lt;p&gt;If you'd rather ask an AI agent, there's a hosted MCP server at &lt;code&gt;https://api.edgrapi.com/mcp&lt;/code&gt;, and Claude or another agent gets the filing links back with the answer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Frequently asked questions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  How do I track congressional stock trades for free?
&lt;/h3&gt;

&lt;p&gt;Use the House Clerk's yearly disclosure index, &lt;code&gt;2026FD.zip&lt;/code&gt; for this year, to list every periodic transaction report, then download each PTR PDF and read its trade rows with a PDF library like &lt;code&gt;pypdf&lt;/code&gt;. It costs nothing and needs no key. Expect about 13% of recent PDFs to be scans with no text layer, which need OCR or get missed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Is there an API for congressional stock trades?
&lt;/h3&gt;

&lt;p&gt;The House has no official API for trades, only the yearly index file and PDFs on the Clerk's site, and the Senate's eFD site has none either. Third-party APIs parse those filings into JSON. Edgrapi, which I build, has a House-only endpoint at 2 credits per call, and others like Quiver Quantitative sell congressional data on paid plans.&lt;/p&gt;

&lt;h3&gt;
  
  
  How late can members of Congress report a stock trade?
&lt;/h3&gt;

&lt;p&gt;Under the STOCK Act, House members must report a transaction over $1,000 within 30 days of learning about it or 45 days after the trade, whichever is earlier, according to the House Ethics Committee. In practice some filings arrive much later. One PTR filed November 23, 2026 listed an NVDA trade dated April 29.&lt;/p&gt;

&lt;h3&gt;
  
  
  What does transaction code P mean on a Form 4?
&lt;/h3&gt;

&lt;p&gt;Code P marks an open-market or private purchase, so the insider spent their own money on the stock. The SEC's Form 4 instructions define it alongside S for sales, A for grants, M for option exercises and F for shares withheld for tax. For an insider trading tracker, P is the code worth alerting on.&lt;/p&gt;

&lt;h3&gt;
  
  
  Where do insider trading trackers get their data?
&lt;/h3&gt;

&lt;p&gt;Almost all of them parse SEC Form 4 filings from EDGAR, which are free XML documents filed within two business days of each trade. Sites like OpenInsider and paid terminals repackage the same filings. You can pull them yourself through &lt;code&gt;data.sec.gov&lt;/code&gt; with a User-Agent header and at most 10 requests per second.&lt;/p&gt;

&lt;h3&gt;
  
  
  Can I track Senate stock trades with Python?
&lt;/h3&gt;

&lt;p&gt;Not easily for free. Senate periodic transaction reports live on efdsearch.senate.gov behind an agreement page and session, and the site has been refusing scripted requests. Your options are browser automation, which is fragile, or a paid data source that covers the Senate. Edgrapi's congress data is House only, so it won't help here.&lt;/p&gt;

&lt;h2&gt;
  
  
  Run the NVDA scripts on your own watchlist this week
&lt;/h2&gt;

&lt;p&gt;Copy the two scripts, swap NVDA for the tickers you care about, and run them once. Then cache the House index and the PDFs you've already read, so the next run only fetches what was filed since. If the PDF downloads become the slow part, that's the point where a hosted API pays for itself.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Mukul Dutt builds &lt;a href="https://edgrapi.com" rel="noopener noreferrer"&gt;Edgrapi&lt;/a&gt;, an API and MCP server for SEC filings, insider trades, 13F holdings, House congressional trades and federal contract data. The scripts in this post are the free version of what Edgrapi runs in production.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>api</category>
      <category>tutorial</category>
      <category>fintech</category>
    </item>
    <item>
      <title>How to parse 13F filings without double-counting every position</title>
      <dc:creator>Mukul Dutt</dc:creator>
      <pubDate>Mon, 07 Sep 2026 19:05:12 +0000</pubDate>
      <link>https://dev.to/paper_andbeyond/how-to-parse-13f-filings-without-double-counting-every-position-47f6</link>
      <guid>https://dev.to/paper_andbeyond/how-to-parse-13f-filings-without-double-counting-every-position-47f6</guid>
      <description>&lt;p&gt;Berkshire Hathaway's latest 13F lists 89 rows. Berkshire holds 29 positions.&lt;/p&gt;

&lt;p&gt;If you built a 13F filing parser that reads the SEC information table and treats each row as one holding, your portfolio is wrong by a factor of three, and nothing in the filing tells you. To parse 13F filings correctly you group rows by CUSIP and put/call flag, not by row and not by issuer name. Berkshire's 89 rows collapse to 29 real positions, a 3.1x over-count, because each sub-manager files its own line for the same security.&lt;/p&gt;

&lt;p&gt;Why does one holding show up as twelve rows?&lt;br&gt;
A 13F-HR reports every US equity position an institutional manager holds, and large filers split investment discretion across sub-managers. Each sub-manager files a separate line for the same security. In Berkshire's filing for the period ending 2026-06-30, Apple occupies 12 rows, Coca-Cola 10, and Bank of America 8. The otherManager field is the only hint, and it points into a separate table.&lt;/p&gt;

&lt;p&gt;Nothing in a row says "this is a fragment." There's no flag, no parent ID, no count. You get twelve Apple rows that each look like a complete position.&lt;/p&gt;

&lt;p&gt;Here's what those rows actually look like once you pull the XML:&lt;/p&gt;

&lt;p&gt;issuer      cusip      shares       value          otherManager&lt;br&gt;
APPLE INC   037833100  ...          ...            4,11&lt;br&gt;
APPLE INC   037833100  ...          ...            2,4,11&lt;br&gt;
APPLE INC   037833100  ...          ...            4,5&lt;br&gt;
... nine more&lt;br&gt;
The SEC's own Form 13F FAQ covers the filing obligations in detail but says nothing about how consumers should reassemble the table. That part is left to you.&lt;/p&gt;

&lt;p&gt;This is not an obscure edge case. The EdgarTools documentation tells its own users to work with holdings aggregated by CUSIP and to touch the raw infotable only when they specifically need per-manager detail. Every serious 13F pipeline solves this. Most quick scripts don't.&lt;/p&gt;

&lt;p&gt;How do you check whether your parser is double-counting?&lt;br&gt;
Run your parser against Berkshire Hathaway, CIK 1067983, accession 0001193125-26-352200, and print the number of positions. If it prints 89 you're counting fragments. If it prints 29 you're aggregating correctly. Berkshire is a useful test case because the over-count is large enough to be obvious and the filing is public, so anyone can reproduce the number.&lt;/p&gt;

&lt;p&gt;Here's a standalone check. No dependencies beyond the standard library:&lt;/p&gt;

&lt;p&gt;import json, urllib.request, collections&lt;br&gt;
import xml.etree.ElementTree as ET&lt;/p&gt;

&lt;p&gt;UA = {"User-Agent": "your-app/1.0 (&lt;a href="mailto:you@example.com"&gt;you@example.com&lt;/a&gt;)"}  # SEC requires a real contact&lt;/p&gt;

&lt;p&gt;def get(url):&lt;br&gt;
    return urllib.request.urlopen(urllib.request.Request(url, headers=UA), timeout=60).read()&lt;/p&gt;

&lt;p&gt;def infotable(cik, accession):&lt;br&gt;
    acc = accession.replace("-", "")&lt;br&gt;
    idx = json.loads(get(f"&lt;a href="https://www.sec.gov/Archives/edgar/data/%7Bcik%7D/%7Bacc%7D/index.json%22)" rel="noopener noreferrer"&gt;https://www.sec.gov/Archives/edgar/data/{cik}/{acc}/index.json")&lt;/a&gt;)&lt;br&gt;
    names = [i["name"] for i in idx["directory"]["item"]]&lt;br&gt;
    xml_name = [n for n in names if n.endswith(".xml") and "primary_doc" not in n][0]&lt;br&gt;
    root = ET.fromstring(get(f"&lt;a href="https://www.sec.gov/Archives/edgar/data/%7Bcik%7D/%7Bacc%7D/%7Bxml_name%7D%22)" rel="noopener noreferrer"&gt;https://www.sec.gov/Archives/edgar/data/{cik}/{acc}/{xml_name}")&lt;/a&gt;)&lt;br&gt;
    ns = {"n": root.tag.split("}")[0].strip("{")} if "}" in root.tag else {}&lt;br&gt;
    q = lambda e, t: e.find(f"n:{t}", ns) if ns else e.find(t)&lt;br&gt;
    rows = []&lt;br&gt;
    for it in (root.findall("n:infoTable", ns) if ns else root.findall("infoTable")):&lt;br&gt;
        pc = q(it, "putCall")&lt;br&gt;
        rows.append({&lt;br&gt;
            "issuer": q(it, "nameOfIssuer").text.strip(),&lt;br&gt;
            "cusip":  q(it, "cusip").text.strip().upper(),&lt;br&gt;
            "value":  float(q(it, "value").text),&lt;br&gt;
            "shares": float(q(q(it, "shrsOrPrnAmt"), "sshPrnamt").text),&lt;br&gt;
            "put_call": pc.text.strip() if pc is not None and pc.text else None,&lt;br&gt;
        })&lt;br&gt;
    return rows&lt;/p&gt;

&lt;p&gt;rows = infotable("1067983", "0001193125-26-352200")&lt;/p&gt;

&lt;h1&gt;
  
  
  The whole fix: group by (CUSIP, putCall). Not by row. Not by issuer name.
&lt;/h1&gt;

&lt;p&gt;agg = collections.defaultdict(lambda: {"shares": 0.0, "value": 0.0, "rows": 0})&lt;br&gt;
for r in rows:&lt;br&gt;
    k = (r["cusip"], r["put_call"] or "")&lt;br&gt;
    a = agg[k]&lt;br&gt;
    a["shares"] += r["shares"]; a["value"] += r["value"]; a["rows"] += 1&lt;br&gt;
    a["issuer"] = r["issuer"]&lt;/p&gt;

&lt;p&gt;print(f"raw rows: {len(rows)}  -&amp;gt;  positions: {len(agg)}")&lt;br&gt;
for k, a in sorted(agg.items(), key=lambda kv: -kv[1]["value"])[:5]:&lt;br&gt;
    print(f"  {a['issuer']:&amp;lt;22} ${a['value']/1e9:&amp;gt;7.2f}B  across {a['rows']:&amp;gt;2} raw rows")&lt;br&gt;
Output, which you can reproduce right now:&lt;/p&gt;

&lt;p&gt;raw rows: 89  -&amp;gt;  positions: 29&lt;br&gt;
  APPLE INC              $  65.95B  across 12 raw rows&lt;br&gt;
  AMERICAN EXPRESS CO    $  51.28B  across  3 raw rows&lt;br&gt;
  COCA COLA CO           $  32.51B  across 10 raw rows&lt;br&gt;
  ALPHABET INC           $  28.16B  across  4 raw rows&lt;br&gt;
  BANK OF AMER CORP      $  27.54B  across  8 raw rows&lt;br&gt;
I verified the aggregate two ways. My raw XML parse and a completely separate production pipeline both return 227,917,808 Apple shares worth $65,950,296,923, and both count 29 positions. Two independent implementations agreeing to the share is decent evidence the grouping is right.&lt;/p&gt;

&lt;p&gt;Why group by CUSIP instead of issuer name?&lt;br&gt;
Because one issuer can legitimately hold several CUSIPs, and merging them destroys real information. Alphabet appears twice in Berkshire's filing under 02079K305 (Class A) and 02079K107 (Class C). Those are different securities with different voting rights and different prices. Collapsing them because the issuer string matches is exactly as wrong as splitting Apple across its 12 sub-manager rows, just in the opposite direction.&lt;/p&gt;

&lt;p&gt;Issuer names are also unreliable as keys. The same company appears as "ALPHABET INC" in one filing and with trailing punctuation, casing differences, or a truncated name in another.&lt;/p&gt;

&lt;p&gt;CUSIP is the identifier the SEC actually requires in the information table. Use it.&lt;/p&gt;

&lt;p&gt;The scale of the share-class problem is easy to underestimate. The SEC's own company_tickers.json contains 10,391 ticker rows mapping to only 8,001 distinct CIKs. About 23% of the tickers in that file are additional share classes of a company already listed.&lt;/p&gt;

&lt;p&gt;What else silently corrupts 13F data?&lt;br&gt;
Three things, and each one produces plausible-looking numbers rather than an error. A putCall row is a bet against the stock, not a holding. Filings before 2023 report value in thousands while newer ones report whole dollars. And amended filings restate positions, so pulling the wrong accession gives you superseded data. None of these throw. All of them change your answer.&lt;/p&gt;

&lt;p&gt;Put and call rows. Options positions sit in the same information table with a putCall value of Put or Call. Sum a Put row into the long book and you'll report a fund as holding a stock it is actually short. This is why the grouping key above is (cusip, put_call) rather than cusip alone. Keep them in separate buckets, and label them when you display them.&lt;/p&gt;

&lt;p&gt;The 2023 units change. Value was reported in thousands before the SEC's amendments took effect, and in whole dollars afterward. Diff a position across that boundary without normalising and it appears to have grown by a factor of 1,000. If your date range straddles it, scale the older side before comparing.&lt;/p&gt;

&lt;p&gt;Amendments. A 13F-HR/A restates part or all of a prior filing. If you index by period rather than by accession, a later amendment can silently overwrite or duplicate positions depending on how you upsert.&lt;/p&gt;

&lt;p&gt;Trap    What it looks like  Fix&lt;br&gt;
Sub-manager rows    89 rows, 29 real positions  Group by CUSIP&lt;br&gt;
Issuer-name grouping    Alphabet A and C merged into one    Key on CUSIP, never the name&lt;br&gt;
putCall rows    Fund reported long a name it is short   Include put/call in the grouping key&lt;br&gt;
Pre-2023 units  Position appears to grow 1000x  Scale thousands to dollars before diffing&lt;br&gt;
Amendments  Positions overwritten or duplicated Index by accession, not period&lt;br&gt;
How do you diff one quarter against the last?&lt;br&gt;
Once positions are aggregated, a quarter-over-quarter diff is a dictionary comparison on the same key. Pull the prior filing, aggregate it identically, then classify each position as new, added, reduced, held or exited. The classification is what makes the data useful, because "Berkshire owns Apple" is not news and "Berkshire added Alphabet and exited Constellation Brands" is.&lt;/p&gt;

&lt;p&gt;def classify(cur, prev):&lt;br&gt;
    out = {}&lt;br&gt;
    for k, a in cur.items():&lt;br&gt;
        p = prev.get(k)&lt;br&gt;
        if not p:                       out[k] = "NEW"&lt;br&gt;
        elif a["shares"] &amp;gt; p["shares"]: out[k] = "ADDED"&lt;br&gt;
        elif a["shares"] &amp;lt; p["shares"]: out[k] = "REDUCED"&lt;br&gt;
        else:                           out[k] = "HELD"&lt;br&gt;
    for k in prev.keys() - cur.keys():  out[k] = "EXITED"&lt;br&gt;
    return out&lt;br&gt;
Running that for Berkshire's Q2 2026 filing against Q1 gives 1 new position, 7 added, 6 reduced, 15 unchanged and 1 exited, across a $299.25 billion portfolio.&lt;/p&gt;

&lt;p&gt;Five of those 29 numbers are worth a headline. The other 24 are noise you now know to ignore.&lt;/p&gt;

&lt;p&gt;What about the 45-day lag?&lt;br&gt;
A 13F is due within 45 days of quarter end, so the data describes what a fund owned up to 45 days before you read it, not what it holds today. Berkshire's Q2 2026 filing covers the period ending 2026-06-30 and was filed 2026-08-14. Treat 13F data as a record of past positioning. It is not a live portfolio feed and it is not a trading signal on its own.&lt;/p&gt;

&lt;p&gt;The lag also means a fund can build and exit a position entirely inside one quarter and you will never see it.&lt;/p&gt;

&lt;p&gt;Two more blind spots worth knowing. 13F covers US-listed equities and some options, so short positions, cash, bonds, and foreign-listed holdings are invisible. And funds can request confidential treatment to delay disclosing a position, which means the table you're reading may be deliberately incomplete.&lt;/p&gt;

&lt;p&gt;Should you build this or use an API?&lt;br&gt;
Build it if you track a handful of funds and enjoy owning the edge cases. The snippet above is 20 lines and works. Use an API if you need many funds, historical diffs, or you'd rather not maintain the units logic and the amendment handling yourself.&lt;/p&gt;

&lt;p&gt;I run one, so treat this as the biased paragraph it is: Edgrapi returns positions already aggregated by CUSIP, put/call flagged and diffed against the prior quarter.&lt;/p&gt;

&lt;p&gt;pip install edgrapi&lt;br&gt;
from edgrapi import Client&lt;/p&gt;

&lt;p&gt;r = Client("edgr_...").holdings("berkshire")&lt;br&gt;
r["positions_count"]   # 29&lt;br&gt;
r["changes"]           # {'new': 1, 'added': 7, 'reduced': 6, 'unchanged': 15, 'exited': 1}&lt;br&gt;
Zero dependencies, free tier is 100 credits a month with no card. The parsing rules in this article are the same either way, and the 20-line version is genuinely fine for a small watchlist.&lt;/p&gt;

&lt;p&gt;Frequently asked questions&lt;br&gt;
Why does my 13F parser show more positions than the fund actually holds?&lt;br&gt;
Because each sub-manager files a separate row for the same security and nothing marks those rows as fragments. Berkshire's latest filing has 89 rows and 29 positions, a 3.1x over-count. Group rows by CUSIP and put/call flag, summing shares and value, and the count resolves to the real number of positions.&lt;/p&gt;

&lt;p&gt;Should I group 13F holdings by CUSIP or by issuer name?&lt;br&gt;
By CUSIP. One issuer can hold several CUSIPs for different share classes, and merging them loses real distinctions. Alphabet appears under 02079K305 for Class A and 02079K107 for Class C in the same filing. Issuer name strings also vary between filings in casing, punctuation and truncation, which makes them unreliable as keys.&lt;/p&gt;

&lt;p&gt;What does putCall mean in a 13F information table?&lt;br&gt;
It marks the row as an options position rather than a share holding. A row with putCall set to Put is a bet against the stock, so summing it into the long book reports a fund as holding a name it is actually short. Include the put/call value in your grouping key and display options positions separately.&lt;/p&gt;

&lt;p&gt;Why do older 13F filings show values 1,000 times smaller?&lt;br&gt;
Value was reported in thousands before the SEC's 2023 amendments and in whole dollars afterward. A position compared across that boundary appears to grow by a factor of 1,000. If your query range straddles the change, normalise the older filings to whole dollars before running any diff or growth calculation.&lt;/p&gt;

&lt;p&gt;How current is 13F data?&lt;br&gt;
It lags by up to 45 days. Managers must file within 45 days of quarter end, so Berkshire's period ending 2026-06-30 was filed 2026-08-14. The filing describes past positioning, not current holdings, and a fund can open and close a position inside a single quarter without it ever appearing.&lt;/p&gt;

&lt;p&gt;Do 13F filings show short positions?&lt;br&gt;
No. 13F covers US-listed equities and certain options only. Short positions, cash, bonds, commodities and foreign-listed holdings are all invisible. A fund can also request confidential treatment to delay disclosing a specific position, so the table may be incomplete by design rather than by error.&lt;/p&gt;

&lt;p&gt;Test your parser against Berkshire before you trust it&lt;br&gt;
Point your parser at CIK 1067983, accession 0001193125-26-352200, and check that it returns 29 positions rather than 89 rows. If it returns 89, add the CUSIP grouping from this article. If it returns 29 but merges Alphabet's two share classes, switch your key from issuer name to CUSIP. Both bugs produce numbers that look reasonable, which is exactly why they survive in production.&lt;/p&gt;

&lt;p&gt;Data in this article comes from public-domain SEC EDGAR filings and was verified on 5 September 2026. None of it is investment advice.&lt;/p&gt;

&lt;p&gt;{&lt;br&gt;
  "&lt;a class="mentioned-user" href="https://dev.to/context"&gt;@context&lt;/a&gt;": "&lt;a href="https://schema.org" rel="noopener noreferrer"&gt;https://schema.org&lt;/a&gt;",&lt;br&gt;
  "&lt;a class="mentioned-user" href="https://dev.to/graph"&gt;@graph&lt;/a&gt;": [&lt;br&gt;
    {&lt;br&gt;
      "@type": "Article",&lt;br&gt;
      "headline": "How to parse 13F filings without double-counting every position",&lt;br&gt;
      "description": "Berkshire's latest 13F has 89 rows and 29 positions. Why naive 13F parsers triple-count, and the Python that fixes it.",&lt;br&gt;
      "datePublished": "2026-09-05",&lt;br&gt;
      "dateModified": "2026-09-05",&lt;br&gt;
      "author": { "&lt;a class="mentioned-user" href="https://dev.to/id"&gt;@id&lt;/a&gt;": "&lt;a href="https://edgrapi.com/#author" rel="noopener noreferrer"&gt;https://edgrapi.com/#author&lt;/a&gt;" },&lt;br&gt;
      "publisher": { "&lt;a class="mentioned-user" href="https://dev.to/id"&gt;@id&lt;/a&gt;": "&lt;a href="https://edgrapi.com/#org" rel="noopener noreferrer"&gt;https://edgrapi.com/#org&lt;/a&gt;" }&lt;br&gt;
    },&lt;br&gt;
    {&lt;br&gt;
      "@type": "Person",&lt;br&gt;
      "&lt;a class="mentioned-user" href="https://dev.to/id"&gt;@id&lt;/a&gt;": "&lt;a href="https://edgrapi.com/#author" rel="noopener noreferrer"&gt;https://edgrapi.com/#author&lt;/a&gt;",&lt;br&gt;
      "name": "Mukul Dutt",&lt;br&gt;
      "jobTitle": "Founder, Edgrapi",&lt;br&gt;
      "sameAs": ["{{AUTHOR_LINKEDIN_URL}}", "&lt;a href="https://edgrapi.com%22" rel="noopener noreferrer"&gt;https://edgrapi.com"&lt;/a&gt;]&lt;br&gt;
    },&lt;br&gt;
    {&lt;br&gt;
      "@type": "Organization",&lt;br&gt;
      "&lt;a class="mentioned-user" href="https://dev.to/id"&gt;@id&lt;/a&gt;": "&lt;a href="https://edgrapi.com/#org" rel="noopener noreferrer"&gt;https://edgrapi.com/#org&lt;/a&gt;",&lt;br&gt;
      "name": "Edgrapi",&lt;br&gt;
      "url": "&lt;a href="https://edgrapi.com" rel="noopener noreferrer"&gt;https://edgrapi.com&lt;/a&gt;"&lt;br&gt;
    },&lt;br&gt;
    {&lt;br&gt;
      "@type": "FAQPage",&lt;br&gt;
      "mainEntity": [&lt;br&gt;
        { "@type": "Question", "name": "Why does my 13F parser show more positions than the fund actually holds?",&lt;br&gt;
          "acceptedAnswer": { "@type": "Answer", "text": "Each sub-manager files a separate row for the same security and nothing marks those rows as fragments. Berkshire's latest filing has 89 rows and 29 positions, a 3.1x over-count. Group rows by CUSIP and put/call flag, summing shares and value." } },&lt;br&gt;
        { "@type": "Question", "name": "Should I group 13F holdings by CUSIP or by issuer name?",&lt;br&gt;
          "acceptedAnswer": { "@type": "Answer", "text": "By CUSIP. One issuer can hold several CUSIPs for different share classes. Alphabet appears under 02079K305 for Class A and 02079K107 for Class C in the same filing. Issuer name strings also vary between filings." } },&lt;br&gt;
        { "@type": "Question", "name": "What does putCall mean in a 13F information table?",&lt;br&gt;
          "acceptedAnswer": { "@type": "Answer", "text": "It marks the row as an options position rather than a share holding. A row with putCall set to Put is a bet against the stock, so summing it into the long book reports a fund as holding a name it is actually short." } },&lt;br&gt;
        { "@type": "Question", "name": "Why do older 13F filings show values 1,000 times smaller?",&lt;br&gt;
          "acceptedAnswer": { "@type": "Answer", "text": "Value was reported in thousands before the SEC's 2023 amendments and in whole dollars afterward. Normalise older filings to whole dollars before running any diff or growth calculation." } },&lt;br&gt;
        { "@type": "Question", "name": "How current is 13F data?",&lt;br&gt;
          "acceptedAnswer": { "@type": "Answer", "text": "It lags by up to 45 days. Managers must file within 45 days of quarter end. The filing describes past positioning, not current holdings." } },&lt;br&gt;
        { "@type": "Question", "name": "Do 13F filings show short positions?",&lt;br&gt;
          "acceptedAnswer": { "@type": "Answer", "text": "No. 13F covers US-listed equities and certain options only. Short positions, cash, bonds and foreign-listed holdings are invisible, and funds can request confidential treatment to delay disclosure." } }&lt;br&gt;
      ]&lt;br&gt;
    }&lt;br&gt;
  ]&lt;br&gt;
}&lt;/p&gt;

</description>
      <category>python</category>
      <category>financeapi</category>
    </item>
    <item>
      <title>Open Graph Image API: generate dynamic og:image URLs in one call</title>
      <dc:creator>Mukul Dutt</dc:creator>
      <pubDate>Thu, 06 Aug 2026 05:12:48 +0000</pubDate>
      <link>https://dev.to/paper_andbeyond/open-graph-image-api-generate-dynamic-ogimage-urls-in-one-call-55c4</link>
      <guid>https://dev.to/paper_andbeyond/open-graph-image-api-generate-dynamic-ogimage-urls-in-one-call-55c4</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://propzapi.com/blog/open-graph-image-api/" rel="noopener noreferrer"&gt;propzapi.com&lt;/a&gt; — cross-posted here.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Every one of your blog posts shares the same flat OG image. That's a thousand links on X and LinkedIn that all look identical, and forgettable. An Open Graph image API fixes that: one template, a per-page image.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it does
&lt;/h2&gt;

&lt;p&gt;You store one 1200×630 layout with &lt;code&gt;{{variables}}&lt;/code&gt;, then sign a URL per post from that post's title. Drop the URL into &lt;code&gt;&amp;lt;meta property="og:image"&amp;gt;&lt;/code&gt;. The image renders the first time a crawler fetches it, then every refetch is cached and free.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why not @vercel/og?
&lt;/h2&gt;

&lt;p&gt;It's great if you're on Next.js and your card is simple. But it renders with Satori, a flexbox-only subset of CSS: no grid, no media queries, no pseudo-elements, and fonts limited to ttf/otf/woff with no ligatures. The day your design needs a font it won't load or a layout it won't do, you're rewriting. A full-Chromium API renders the CSS you already wrote.&lt;/p&gt;

&lt;h2&gt;
  
  
  The cost trap people miss
&lt;/h2&gt;

&lt;p&gt;Facebook, Slack, LinkedIn and X hammer your og:image on every share and re-share. If you paid per fetch, a viral post would be a surprise bill. Sign the URL for free, render once on first fetch (one credit), and cache serves every share after. Cost tracks how many distinct images you make, not how popular they get.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why isn't my og:image updating?
&lt;/h2&gt;

&lt;p&gt;Almost always platform caching, not your API. Facebook and LinkedIn scrape once and hold it — force a re-scrape in their debugger. And the URL has to be absolute; a relative path works in your browser but not for an external crawler.&lt;/p&gt;

&lt;p&gt;Full guide — sizes, the four ways to generate them, and the debugger workflow — in the &lt;a href="https://propzapi.com/blog/open-graph-image-api/" rel="noopener noreferrer"&gt;Open Graph Image API guide&lt;/a&gt;, built on &lt;a href="https://propzapi.com" rel="noopener noreferrer"&gt;propzapi&lt;/a&gt;, which also does HTML-to-image, screenshots, and one-page PDFs.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>api</category>
      <category>seo</category>
      <category>nextjs</category>
    </item>
    <item>
      <title>HTML to PDF API: convert HTML to PDF in one call</title>
      <dc:creator>Mukul Dutt</dc:creator>
      <pubDate>Thu, 06 Aug 2026 05:09:58 +0000</pubDate>
      <link>https://dev.to/paper_andbeyond/html-to-pdf-api-convert-html-to-pdf-in-one-call-6dk</link>
      <guid>https://dev.to/paper_andbeyond/html-to-pdf-api-convert-html-to-pdf-in-one-call-6dk</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://propzapi.com/blog/html-to-pdf-api/" rel="noopener noreferrer"&gt;propzapi.com&lt;/a&gt; — cross-posted here.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;wkhtmltopdf is dead. The repo was archived in 2023, the last release was 2020, and it ships an unpatched critical SSRF (CVE-2022-35583). If your PDF pipeline still runs on it, you're shipping a 2012 browser engine with a security hole. Here's the modern version.&lt;/p&gt;

&lt;h2&gt;
  
  
  What an HTML to PDF API does
&lt;/h2&gt;

&lt;p&gt;You send HTML (or a stored template id plus data), it renders the page in headless Chromium, and returns a URL to a finished PDF. Chromium prints with the same engine that draws your page in a browser, so your flexbox, grid, and web fonts come out right — no 2012 WebKit fork mangling the layout.&lt;/p&gt;

&lt;h2&gt;
  
  
  One call
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl https://api.propzapi.com/v1/images &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s2"&gt;"X-API-Key: pk_live_…"&lt;/span&gt; &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s1"&gt;'{"template":"tpl_…","format":"pdf","data":{"number":"1042","total":"$4,200.00"}}'&lt;/span&gt;
&lt;span class="c"&gt;# → { "url": "https://images.propzapi.com/img_….pdf", "width":794, "height":1123, "format":"pdf", "bytes":6679 }&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Store an invoice or certificate template once with &lt;code&gt;{{variables}}&lt;/code&gt;, then render per record. A common wiring: a payment webhook fires, your handler POSTs the template with that order's data, and you email the returned PDF URL. Billed on delivery — a failed render costs nothing.&lt;/p&gt;

&lt;h2&gt;
  
  
  The gotchas that bite everyone
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Page size is CSS.&lt;/strong&gt; A4 is 794×1123px at 96dpi, US Letter is 816×1056. Set margins with the &lt;code&gt;@page&lt;/code&gt; rule.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Backgrounds get stripped by default&lt;/strong&gt; — add &lt;code&gt;print-color-adjust: exact&lt;/code&gt; or your dark header prints white.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fonts and images&lt;/strong&gt;: wait for webfonts to load before rendering, and use absolute URLs for anything the PDF shows (the render server has no session to authenticate with).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  When not to reach for it
&lt;/h2&gt;

&lt;p&gt;For a 40-page contract with running headers, page numbers, and footnotes, use a paged-media engine like Prince — Chromium's page-break control is uneven. Chromium is built for single-page outputs: invoices, receipts, tickets, certificates, one-page reports.&lt;/p&gt;

&lt;p&gt;I wrote the full guide — self-host Puppeteer vs hosted, a comparison table, the WeasyPrint option, and every gotcha with its fix — in the &lt;a href="https://propzapi.com/blog/html-to-pdf-api/" rel="noopener noreferrer"&gt;HTML to PDF API guide&lt;/a&gt;, built on &lt;a href="https://propzapi.com" rel="noopener noreferrer"&gt;propzapi&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>api</category>
      <category>node</category>
      <category>python</category>
    </item>
    <item>
      <title>Bannerbear alternative: a pay-as-you-go image generation API</title>
      <dc:creator>Mukul Dutt</dc:creator>
      <pubDate>Thu, 06 Aug 2026 05:07:00 +0000</pubDate>
      <link>https://dev.to/paper_andbeyond/bannerbear-alternative-a-pay-as-you-go-image-generation-api-4i6n</link>
      <guid>https://dev.to/paper_andbeyond/bannerbear-alternative-a-pay-as-you-go-image-generation-api-4i6n</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://propzapi.com/blog/bannerbear-alternative/" rel="noopener noreferrer"&gt;propzapi.com&lt;/a&gt; — cross-posted here.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Bannerbear is a good product. It's also a $49-a-month subscription and a visual editor, and neither of those is what every team wants. If you're a developer who renders images from data and would rather write HTML than click a canvas, here's the honest comparison.&lt;/p&gt;

&lt;h2&gt;
  
  
  What each one is
&lt;/h2&gt;

&lt;p&gt;Bannerbear is a mature no-code media platform: design in a drag-and-drop editor, then generate images, video, and PDFs over an API. It has real strengths I won't pretend away — a video API, AI face-detection (2 credits per image), Smart Crop, batch generation, and years of production maturity.&lt;/p&gt;

&lt;p&gt;propzapi is a developer-first image API: you store your own HTML/CSS templates with &lt;code&gt;{{variables}}&lt;/code&gt;, render them to PNG/JPEG/WebP/PDF in headless Chromium, screenshot any URL, and pay per image instead of a subscription. It ships a first-party MCP server, so an agent can render an image as a tool call.&lt;/p&gt;

&lt;h2&gt;
  
  
  The price math
&lt;/h2&gt;

&lt;p&gt;Bannerbear's entry tier is $49/mo for 1,000 images (about $0.049 each), and you pay it whether you render 40 or 1,000. propzapi's $5 pack is about $0.033 an image and never expires — so 200 images is a few dollars, not a monthly floor. The subscription only pulls ahead once your steady volume clears a few hundred a month.&lt;/p&gt;

&lt;h2&gt;
  
  
  Who should pick which
&lt;/h2&gt;

&lt;p&gt;Choose Bannerbear if a non-developer owns the templates, you need video, or you want AI face-detection for user-uploaded photos. Choose propzapi if you render from data in code, want no monthly floor, and would rather write real CSS than work around an editor's limits.&lt;/p&gt;

&lt;p&gt;I did the full feature-by-feature table, the sourced capability breakdown (video, face-detect, Smart Crop — all from Bannerbear's own docs), and a migration guide in the &lt;a href="https://propzapi.com/blog/bannerbear-alternative/" rel="noopener noreferrer"&gt;full comparison&lt;/a&gt;. It's built on &lt;a href="https://propzapi.com" rel="noopener noreferrer"&gt;propzapi&lt;/a&gt;, a pay-as-you-go image generation API for developers and agents.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>api</category>
      <category>saas</category>
      <category>productivity</category>
    </item>
    <item>
      <title>HTML to Image API: turn HTML and CSS into a PNG in one call</title>
      <dc:creator>Mukul Dutt</dc:creator>
      <pubDate>Thu, 06 Aug 2026 05:03:02 +0000</pubDate>
      <link>https://dev.to/paper_andbeyond/html-to-image-api-turn-html-and-css-into-a-png-in-one-call-1g2j</link>
      <guid>https://dev.to/paper_andbeyond/html-to-image-api-turn-html-and-css-into-a-png-in-one-call-1g2j</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://propzapi.com/blog/html-to-image-api/" rel="noopener noreferrer"&gt;propzapi.com&lt;/a&gt; — cross-posted here.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;You already wrote the layout. It's a &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; with some CSS, and it looks right in your browser. Now you need it as a PNG, a few hundred times, one per row in your database. That gap, between a page you can see and an image file you can host, is the whole job.&lt;/p&gt;

&lt;h2&gt;
  
  
  What an HTML to image API actually does
&lt;/h2&gt;

&lt;p&gt;You POST HTML (or a stored template id plus data), it renders that markup in real headless Chromium, and hands back a hosted PNG/JPEG/WebP URL. No browser to install, no canvas library, no fonts to wrangle. Your CSS in, a picture out.&lt;/p&gt;

&lt;p&gt;The reason to reach for a service instead of a browser library like &lt;code&gt;html-to-image&lt;/code&gt; or &lt;code&gt;html2canvas&lt;/code&gt;: those run in the user's browser and taint the canvas the moment a cross-origin image or a webfont touches it, so the asset shows in the preview and then silently vanishes from the export. Server-side rendering sidesteps that entirely.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why not just run Puppeteer yourself?
&lt;/h2&gt;

&lt;p&gt;You can. The script is an afternoon. Then production shows up: a single headless Chrome instance runs 300–500MB of RAM and climbs past 1GB over time, needs system fonts installed, and crashes under concurrency. On Lambda the full Chromium binary blows the 250MB package limit, so you're on &lt;code&gt;@sparticuz/chromium&lt;/code&gt; with a 2GB function and a bumped timeout. None of it is hard. It's just a browser you now operate, forever, to make pictures.&lt;/p&gt;

&lt;h2&gt;
  
  
  One call
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl https://api.propzapi.com/v1/images &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s2"&gt;"X-API-Key: pk_live_…"&lt;/span&gt; &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s1"&gt;'{"template":"og-article","data":{"title":"Ship an image for every row"},"format":"png"}'&lt;/span&gt;
&lt;span class="c"&gt;# → { "url": "https://images.propzapi.com/img_….png", "width":1200, "height":630, "bytes":95126 }&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Store your own HTML once (with &lt;code&gt;{{variables}}&lt;/code&gt;), then render it per record. Because it's full Chromium, whatever CSS works in your browser works in the image — flexbox, grid, gradients, web fonts. Not a stripped-down subset of it.&lt;/p&gt;

&lt;h2&gt;
  
  
  PNG, WebP or JPEG?
&lt;/h2&gt;

&lt;p&gt;PNG for text and sharp edges, since it's lossless. WebP when there's a photo or a gradient in the frame (about 26% smaller). JPEG only for mostly-photo art. Set &lt;code&gt;format&lt;/code&gt; and &lt;code&gt;scale&lt;/code&gt; (2 for retina) per call.&lt;/p&gt;

&lt;h2&gt;
  
  
  When you don't need it
&lt;/h2&gt;

&lt;p&gt;If you have five fixed images that never change, make them by hand in Figma and move on. An API earns its place when the images are per-record and unbounded — a card per post, an invoice per order, a certificate per user.&lt;/p&gt;

&lt;p&gt;I wrote the full version — the self-host cost breakdown, a four-way comparison table, formats with real byte sizes, and the honest "when not to" — in the &lt;a href="https://propzapi.com/blog/html-to-image-api/" rel="noopener noreferrer"&gt;full HTML to Image API guide&lt;/a&gt;. It's built on &lt;a href="https://propzapi.com" rel="noopener noreferrer"&gt;propzapi&lt;/a&gt;, which also screenshots any URL, exports one-page PDFs, and ships an MCP server so an agent can render an image as a tool call.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>api</category>
      <category>tutorial</category>
      <category>showdev</category>
    </item>
  </channel>
</rss>
