Package: sec-parser
sec-parserEssentials ➔Health ➔Quality ➔Distribution ➔Community ➔Parse SEC EDGAR HTML documents into a tree of elements that correspond to the visual structure of the document.See Demo|Read Docs|Join Discussions|Join DiscordOverviewThesec-parserproject simplifies extracting meaningful information from SEC EDGAR HTML documents by organizing them into semantic elements and a tree structure. Semantic elements might include section titles, paragraphs, and tables, each classified for easier data manipulation. This forms a semantic tree that corresponds to the visual and informational structure of the document. If you're familiar with theImage Semantic Segmentationconcept, it's the same but applied to HTML documents.This tool is especially beneficial for Artificial Intelligence (AI), Machine Learning (ML), and Large Language Models (LLM) applications by streamlining data pre-processing and feature extraction.Explore theDemoRead theDocumentationJoin theDiscussionsto get help, propose ideas, or chat with the communityBecome part of ourDiscordcommunityReport bugs inIssuesStay updated and contribute to our project's direction inAnnouncementsandRoadmapLearn How toContributeKey Use-Casessec-parseris versatile and can be applied in various scenarios, including but not limited to:Financial and Regulatory AnalysisFinancial Analysis: Extract financial data from 10-Q and 10-K filings for quantitative modeling.Risk Assessment: Evaluate risk factors or Management's Discussion and Analysis sections for qualitative analysis.Regulatory Compliance: Assist in automating compliance checks for the legal teams.Flexible Filtering: Easily filter SEC documents by sections and types, giving you precisely the data you need.Analytics and Data ScienceAcademic Research: Facilitate large-scale studies involving public financial disclosures, sentiment analysis, or corporate governance exploratory.Analytics Ready: Integrate parsed data seamlessly into popular analytics tools for further analysis and visualization.AI and Machine LearningCutting-Edge AI for SEC EDGAR: Apply advanced AI techniques like MemWalker to navigate and extract and transform complex information from SEC documents efficiently. Learn more in our blog post:Cutting-Edge AI for SEC EDGAR: Introducing MemWalker.AI Applications: Leverage parsed data for various AI tasks such as text summarization, sentiment analysis, and named entity recognition.Data Augmentation: Use authentic financial text to train and test machine learning models.Causal AICausal Analysis: Use parsed data to understand cause-effect relationships in financial data, beyond mere correlations.Predictive Modeling: Enhance predictive models by incorporating causal relationships, leading to more robust and reliable predictions.Decision Making: Aid decision-making processes by providing insights into the potential impact of different actions, based on causal relationships identified in the data.Large Language ModelsLLM Compatible: Use parsed data to facilitate complex NLU tasks with Large Language Models like ChatGPT, including question-answering, language translation, and information retrieval.These use-cases demonstrate the flexibility and power ofsec-parserin handling both traditional data extraction tasks and facilitating more advanced AI-driven analysis.Disclaimer[!IMPORTANT]
This project,sec-parser, is an independent, open-source initiative and has no affiliation, endorsement, or verification by the United States Securities and Exchange Commission (SEC). It utilizes public APIs and data provided by the SEC solely for research, informational, and educational objectives. This tool is not intended for financial advisement or as a substitute for professional investment advice or compliance with securities regulations. The creators and maintainers make no warranties, expressed or implied, about the accuracy, completeness, or reliability of the data and analyses presented. Use this software at your own risk. For accurate and comprehensive financial analysis, consult with qualified financial professionals and comply with all relevant legal requirements. The project maintainers and contributors are not liable for any financial or legal consequences arising from the use of this tool.Getting StartedThis guide will walk you through the process of installing thesec-parserpackage and using it to extract the "Segment Operating Performance" section as a semantic tree from the latest Apple 10-Q filing.[!TIP]
To run the example code in a ready-to-code environment, you can use GitHub Codespaces. Click the button below to open the example code below in a codespace and start experimenting withsec-parser:InstallationFirst, install thesec-parserpackage using pip:pipinstallsec-parserIn order to run the example code in this README, you'll also need thesec_downloaderpackage:pipinstallsec-downloaderUsageOnce you've installed the necessary packages, you can start by downloading the filing from the SEC EDGAR website. Here's how you can do it:fromsec_downloaderimportDownloader# Initialize the downloader with your company name and emaildl=Downloader("MyCompanyName","email@example.com")# Download the latest 10-Q filing for Applehtml=dl.get_filing_html(ticker="AAPL",form="10-Q")[!NOTE]
The company name and email address are used to form a user-agent string that adheres to the SEC EDGAR's fair access policy for programmatic downloading.SourceNow, we can parse the filing HTML into a list of semantic elements:```python``Utility function to make the example code a bit more compactdef print_first_n_lines(text: str, *, n: int):
print("\n".join(text.split("\n")[:n]), "...", sep="\n")```python
import sec_parser as sp

elements: list = sp.Edgar10QParser().parse(html)

demo_output: str = sp.render(elements)
print_first_n_lines(demo_output, n=7)TopSectionTitle:PART I  —  FINANCIAL INFORMATIONTopSectionTitle:Item 1.    Financial StatementsTitleElement:CONDENSED CONSOLIDATED STATEMENTS OF OPERATIONS (Unaudited)SupplementaryText:(In millions, except number of ...housands and per share amounts)TableElement:Table with 24 rows, 80 numbers, and 1058 characters.SupplementaryText:See accompanying Notes to Conde...solidated Financial Statements.TitleElement:CONDENSED CONSOLIDATED STATEMEN...OMPREHENSIVE INCOME (Unaudited)
...We can also construct a semantic tree to allow for easy filtering by parent sections:tree=sp.TreeBuilder().build(elements)demo_output:str=sp.render(tree)print_first_n_lines(demo_output,n=7)TopSectionTitle:PART I  —  FINANCIAL INFORMATION
├──TopSectionTitle:Item 1.    Financial Statements
│   ├──TitleElement:CONDENSED CONSOLIDATED STATEMENTS OF OPERATIONS (Unaudited)
│   │   ├──SupplementaryText:(In millions, except number of ...housands and per share amounts)
│   │   ├──TableElement:Table with 24 rows, 80 numbers, and 1058 characters.
│   │   ├──SupplementaryText:See accompanying Notes to Conde...solidated Financial Statements.
│   ├──TitleElement:CONDENSED CONSOLIDATED STATEMEN...OMPREHENSIVE INCOME (Unaudited)
...For more examples and advanced usage, you can continue learning how to usesec-parserby referring to theUser Guide,Developer Guide, andDocumentation.What's Next?You've successfully parsed an SEC document into semantic elements and arranged them into a tree structure. To further analyze this data with analytics or AI, you can use any tool of your choice.For a tailored experience, consider using our free and open-source library for AI-powered financial analysis:pipinstallsec-aiExploresec-aion GitHubBest PracticesHow to Import Modules In Your CodeTo ensure your code remains functional even when we change the internal structure ofsec-parser, it's recommended to avoid deep imports. Here is an example of a deep import:from sec_parser.semantic_tree.internal_utils.core import SomeInternalClassHere are the suggested ways to import modules fromsec-parser:Root Import (prefix)import sec_parser as sp. This imports the main package assp. You can then access its functionalities usingsp.prefix.Root Import (direct)from sec_parser import SomeClass: This allows you to directly useSomeClasswithout any prefix.Submodule Import (prefix)import sec_parser.semantic_tree: This imports thesemantic_treesubmodule, and you can access its classes and functions usingsemantic_tree.prefix.Submodule Import (direct)from sec_parser.semantic_tree import SomeClass: This imports a specific classSomeClassfrom thesemantic_treesubmodule.[!NOTE]
The main packagesec_parsercontains only the most common functionalities. For specialized tasks, please use submodule or submodule-level imports.ContributingFor information about setting up the development environment, coding standards, and contribution workflows, please refer to ourCONTRIBUTING.mdguide.LicenseThis project is licensed under the MIT License - see theLICENSEfile for details.