|
| 1 | +# EdgarTools SEO Code Snippets |
| 2 | + |
| 3 | +Reusable, tested code snippets for use across blog posts, notebooks, README, and documentation. |
| 4 | +Each snippet is self-contained, produces meaningful output, and works with edgartools 5.16+. |
| 5 | + |
| 6 | +**Core message**: Free, no API key, 3 lines of Python. |
| 7 | + |
| 8 | +--- |
| 9 | + |
| 10 | +## 1. Get a Company's Financial Statements |
| 11 | + |
| 12 | +```python |
| 13 | +from edgar import Company |
| 14 | + |
| 15 | +tenk = Company("AAPL").get_filings(form="10-K")[0].obj() |
| 16 | +print(tenk.financials.income_statement()) |
| 17 | +``` |
| 18 | + |
| 19 | +--- |
| 20 | + |
| 21 | +## 2. Search and Browse Filings |
| 22 | + |
| 23 | +```python |
| 24 | +from edgar import Company |
| 25 | + |
| 26 | +filings = Company("MSFT").get_filings(form="10-K") |
| 27 | +filing = filings[0] |
| 28 | +filing.open() # Opens in browser |
| 29 | +``` |
| 30 | + |
| 31 | +--- |
| 32 | + |
| 33 | +## 3. Get Insider Trading Data |
| 34 | + |
| 35 | +```python |
| 36 | +from edgar import Company |
| 37 | + |
| 38 | +form4s = Company("TSLA").get_filings(form="4").head(5) |
| 39 | +for f in form4s: |
| 40 | + print(f.obj()) |
| 41 | +``` |
| 42 | + |
| 43 | +--- |
| 44 | + |
| 45 | +## 4. Track Hedge Fund Holdings (13F) |
| 46 | + |
| 47 | +```python |
| 48 | +from edgar import Company |
| 49 | + |
| 50 | +thirteenf = Company(1423053).get_filings(form="13F-HR")[0].obj() # Citadel Advisors |
| 51 | +print(thirteenf.holdings) |
| 52 | +``` |
| 53 | + |
| 54 | +--- |
| 55 | + |
| 56 | +## 5. Get Today's SEC Filings |
| 57 | + |
| 58 | +```python |
| 59 | +from edgar import get_current_filings |
| 60 | + |
| 61 | +filings = get_current_filings().filter(form="8-K") |
| 62 | +print(filings) |
| 63 | +``` |
| 64 | + |
| 65 | +--- |
| 66 | + |
| 67 | +## 6. Get Revenue Across Years |
| 68 | + |
| 69 | +```python |
| 70 | +from edgar import Company |
| 71 | + |
| 72 | +facts = Company("GOOG").get_facts() |
| 73 | +print(facts.get_revenue()) |
| 74 | +``` |
| 75 | + |
| 76 | +--- |
| 77 | + |
| 78 | +## 7. Comparison: edgartools vs sec-api |
| 79 | + |
| 80 | +```python |
| 81 | +# edgartools — free, no API key, 3 lines |
| 82 | +from edgar import Company |
| 83 | + |
| 84 | +income = Company("AAPL").get_filings(form="10-K")[0].obj().financials.income_statement() |
| 85 | +print(income) |
| 86 | + |
| 87 | +# sec-api — $55-$239/month, API key required, 15+ lines |
| 88 | +# from sec_api import QueryApi, XbrlApi |
| 89 | +# api = QueryApi(api_key="YOUR_PAID_API_KEY") |
| 90 | +# query = {"query": {"query_string": {"query": 'ticker:AAPL AND formType:"10-K"'}}} |
| 91 | +# filings = api.get_filings(query) |
| 92 | +# xbrl_api = XbrlApi(api_key="YOUR_PAID_API_KEY") |
| 93 | +# xbrl_json = xbrl_api.xbrl_to_json(accession_no=filings[0]["accessionNo"]) |
| 94 | +# income = xbrl_json["StatementsOfIncome"] |
| 95 | +# ... more parsing needed ... |
| 96 | +``` |
0 commit comments