Git Product home page Git Product logo

sec-api-io's Introduction

sec-api-io

GitHub Workflow Status PyPI - Python Version PyPI version Licence

Unofficial wrapper for the sec-api.io API. Built with nbdev.

Install and Setup

Run in terminal:

pip install sec_api_io

How to use

(Optional) Set API key with .env file

It’s highly recommended to set your API key in a .env file to avoid setting it in the code.

  1. Make a copy of the .env.template file in the root directory of the project.
  2. Rename the copied file to .env.
  3. Open the .env file and locate the SECAPIO_API_KEY variable.
  4. Fill in the value for the SECAPIO_API_KEY variable.
    • You can obtain a free key from sec-api.io.
    • Note: The first 100 requests are free.
  5. Save the .env file next to your notebook or script.

Important Note: Depending on your geographical location, you might need to use a VPN set to a United States location to access sec-api.io API.

Let’s load the API key from .env file into the environment variable SECAPIO_API_KEY

!pip install -q python-dotenv
from dotenv import load_dotenv

load_dotenv() # Load the API key from .env file into the environment variable SECAPIO_API_KEY
True
import os 
from dotenv import load_dotenv

if 'SECAPIO_API_KEY' not in os.environ:
    assert load_dotenv()
    
assert 'SECAPIO_API_KEY' in os.environ
import os 
from dotenv import load_dotenv

if 'SECAPIO_API_KEY' not in os.environ:
    assert load_dotenv()
    
assert 'SECAPIO_API_KEY' in os.environ
assert os.environ['SECAPIO_API_KEY'].strip()

Get latest 10-Q report by ticker

from sec_api_io.secapio_data_retriever import SecapioDataRetriever

retriever = SecapioDataRetriever()
# retriever = SecapioDataRetriever(api_key=...) # If you don't want to use .env file

metadata = retriever.retrieve_report_metadata('10-Q', latest_from_ticker='AAPL')
url = metadata["linkToFilingDetails"]

assert url.startswith('https://www.sec.gov/Archives/edgar/data/')
url
'https://www.sec.gov/Archives/edgar/data/320193/000032019323000077/aapl-20230701.htm'

Download 10-Q HTML split into sections

html = retriever.get_report_html('10-Q', url)
assert html
for line in html.splitlines():
    print(line[:65] + '...')
<top-level-section-separator id="part1item1" title="Financial Statemen...
<span style="color:#000000;font-family:'Helvetica',sans-serif;fon...
<top-level-section-separator id="part1item2" title="Management's Discu...
<span style="color:#000000;font-family:'Helvetica',sans-serif;fon...
<top-level-section-separator id="part1item3" title="Quantitative and Q...
<span style="color:#000000;font-family:'Helvetica',sans-serif;fon...
<top-level-section-separator id="part1item4" title="Controls and Proce...
<span style="color:#000000;font-family:'Helvetica',sans-serif;fon...
<top-level-section-separator id="part2item1" title="Legal Proceedings"...
<span style="color:#000000;font-family:'Helvetica',sans-serif;fon...
<top-level-section-separator id="part2item1a" title="Risk Factors" com...
<span style="color:#000000;font-family:'Helvetica',sans-serif;fon...
<top-level-section-separator id="part2item2" title="Unregistered Sales...
<span style="color:#000000;font-family:'Helvetica',sans-serif;fon...
<top-level-section-separator id="part2item3" title="Defaults Upon Seni...
<span style="color:#000000;font-family:'Helvetica',sans-serif;fon...
<top-level-section-separator id="part2item4" title="Mine Safety Disclo...
<span style="color:#000000;font-family:'Helvetica',sans-serif;fon...
<top-level-section-separator id="part2item5" title="Other Information"...
<span style="color:#000000;font-family:'Helvetica',sans-serif;fon...
<top-level-section-separator id="part2item6" title="Exhibits" comment=...
<span style="color:#000000;font-family:'Helvetica',sans-serif;fon...

Contributing

Follow these steps to install the project locally for development:

  1. Install the project with the command pip install -e ".[dev]".

Note We highly recommend using virtual environments for Python development. If you’d like to use virtual environments, follow these steps instead: - Create a virtual environment python3 -m venv .venv - Activate the virtual environment source .venv/bin/activate - Install the project with the command pip install -e ".[dev]"

sec-api-io's People

Contributors

elijas avatar inf800 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

sec-api-io's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.