edgartools icon indicating copy to clipboard operation
edgartools copied to clipboard

How do you query entire tables in the SEC filing

Open Rud854 opened this issue 1 year ago • 7 comments

Based on the description of Edgartools, it is very convenient to query facts and so forth. But how would you lets say query an entire table (not financial statements like shown below.

The original code for this:

from edgar.xbrl import XBRL company = Company("XOM") filing = company.latest("10-K") xb = filing.xbrl() results = (xb.query() .by_concept("us-gaap:ScheduleOfInventoryCurrentTableTextBlock") ) results

Result Dataframe:

Image

Whats really in the XBRL

Image

Here is the original source https://www.sec.gov/ix?doc=/Archives/edgar/data/0000034088/000003408825000010/xom-20241231.htm#fact-identifier-1154

To me I think this is a important issue for filings because theres a lot of useful little tables for specific sectors like energy, and tech (data centers) and so forth. So if there is a solution, would there be documentation in the manual then?

Rud854 avatar Jul 02 '25 22:07 Rud854

I think you mean query for the concept and render the HTML if it is a TableBlock. I think that is doable as a feature request

dgunning avatar Jul 03 '25 10:07 dgunning

I agree this could be a feature request but would this be allowed afterwards be like

df = textblock.todataframe()

Or be allowed in such a way to allow to parse the table out from the textblock to put in a nice dataframe.

Rud854 avatar Jul 03 '25 11:07 Rud854

Triage Summary

Thank you for this feature request! This is a valuable enhancement that would make industry-specific tables much more accessible.

Classification

Type: Feature Request (Enhancement) Priority: MEDIUM (P2) - Priority Score: 16 Target Release: v4.30.0 or v4.31.0 (Q1 2025) Estimated Effort: 2 days (Medium) Tracking: Created internal issue edgartools-a8d

Analysis

This feature aligns well with EdgarTools' mission of making SEC data elegantly accessible. It would:

✅ Fill an API Gap: TableTextBlock concepts currently return metadata, not the actual table data ✅ Beginner-Friendly: Extends familiar .query().by_concept() API with .extract_tables() ✅ Leverage Existing Code: EdgarTools already has production-ready table extraction (TableNode.to_dataframe()) ✅ Pandas-First: Natural integration with data science workflows

Proposed API Design

We're considering an API like this:

from edgar import Company

company = Company("XOM")
filing = company.latest("10-K")
xbrl = filing.xbrl()

# Extract tables from TableTextBlock concept
tables = (xbrl.query()
          .by_concept("us-gaap:ScheduleOfInventoryCurrentTableTextBlock")
          .extract_tables())  # Returns List[pd.DataFrame]

# Access first table
inventory_table = tables[0]
print(inventory_table.head())

Design Questions for Community Feedback

Before implementing, we'd like input on:

  1. Method naming: .extract_tables(), .to_dataframe(), or .render_tables()?
  2. Multi-table handling: How should we handle concepts with multiple tables?
    • Return list of DataFrames (most flexible)
    • Return merged DataFrame with multi-index
    • Require explicit table index selection
  3. Missing table behavior: What if concept exists but no table found?
    • Return None
    • Raise TableNotFound exception
    • Return empty DataFrame

Current Workaround

While we evaluate this feature, you can extract tables manually using the document API:

from edgar import Company

company = Company("XOM")
filing = company.latest("10-K")

# Parse the HTML document
doc = filing.document()

# Find tables - the document tree provides access to all tables
# You can then use .to_dataframe() on individual table nodes
# You'll need to identify which table corresponds to your concept

Timeline

  • Triage Complete: ✅ (This update)
  • API Design Discussion: Next 1-2 weeks (community feedback welcome!)
  • Implementation: Planned for v4.30.0 or v4.31.0 (Q1 2025) depending on prioritization
  • Tracking: Created internal tracking issue (edgartools-a8d)

We appreciate the detailed example in your issue - it helps us understand the use case perfectly! Feel free to share any additional thoughts on the API design questions above.


Related: This feature would also enable extraction of other industry-specific tables (segment data for tech companies, loan schedules for banks, property details for REITs, etc.).

dgunning avatar Nov 25 '25 12:11 dgunning

Yes, this is a genius plan to extract all the small tables and then access each specific table.

But Ill answer all three questions

  1. extract.tables is probably the simplest to remember personally.
  2. I would return the list of DataFrames
  3. I think the TableNotFound would be the easiest one for users. This way users can report errors with the API faster.

Rud854 avatar Nov 27 '25 18:11 Rud854

We already have the fundamental code to do this in edgartools so it's possible to find these blocks. There may be some complication in rendering to data frames but I think some imperfect code already exists for this

Are you starting from already knowing the key you want to search by e.g. "us-gaap:ScheduleOfInventoryCurrentTableTextBlock"

?

dgunning avatar Nov 27 '25 19:11 dgunning

So this was the issue I had. I didn't know initially how to do it. So I queried by the exact name yes

Rud854 avatar Nov 27 '25 23:11 Rud854

See #652

mpreiss9 avatar Feb 18 '26 03:02 mpreiss9