SecParse API SDK for Python (secparse.com)
Project description
SecParse SDK
Python SDK for SecParse - Query and subscribe to SEC EDGAR filing data via GraphQL.
Features
- Simple and intuitive API
- Support for GraphQL queries
- WebSocket-based subscriptions for real-time data
- Async/await support
- Built-in API key authentication
- Type-safe error handling
Installation
pip install secparse
Quick Start
Queries
Query SEC filing data using GraphQL:
import asyncio
from secparse import SecParseClient
async def main():
async with SecParseClient(api_key="your-api-key") as client:
# Query for Assets facts from Apple Inc. (CIK: 63908)
result = await client.query("""
query {
Fact(
where: {
Concept: {name: {_eq: "Assets"}, namespace: {_eq: "us-gaap"}}
isSuperseded: {_eq: false}
Submission: {filerCik: {_eq: "63908"}}
FactSegments_aggregate: {count: {predicate: {_eq: 0}}}
}
order_by: {effectiveDate: asc}
) {
effectiveDate
Submission {
Filer {
name
cik
}
type
accessionNumber
}
valueNumber
measure
}
}
""")
print(result)
asyncio.run(main())
Queries with Variables
Use variables for dynamic queries:
import asyncio
from secparse import SecParseClient
async def main():
async with SecParseClient(api_key="your-api-key") as client:
result = await client.query(
"""
query GetFactsByCik($cik: String!, $conceptName: String!) {
Fact(
where: {
Concept: {name: {_eq: $conceptName}, namespace: {_eq: "us-gaap"}}
isSuperseded: {_eq: false}
Submission: {filerCik: {_eq: $cik}}
}
limit: 10
order_by: {effectiveDate: desc}
) {
effectiveDate
valueNumber
Submission {
Filer {
name
cik
}
}
}
}
""",
variables={
"cik": "63908", # Apple Inc.
"conceptName": "Assets"
}
)
print(result)
asyncio.run(main())
Subscriptions
Subscribe to real-time SEC filing updates:
import asyncio
from secparse import SecParseClient
async def main():
client = SecParseClient(api_key="your-api-key")
try:
# Subscribe to new submissions from Apple Inc.
async for data in client.subscribe("""
subscription {
Submission(where: {Filer: {cik: {_eq: "63908"}}}) {
accessionNumber
acceptedDate
}
}
"""):
print(f"New submission: {data}")
finally:
await client.close()
asyncio.run(main())
Subscriptions with Variables
import asyncio
from secparse import SecParseClient
async def main():
client = SecParseClient(api_key="your-api-key")
try:
async for data in client.subscribe(
"""
subscription GetSubmissions($cik: String!) {
Submission(where: {Filer: {cik: {_eq: $cik}}}) {
accessionNumber
acceptedDate
type
Filer {
name
cik
}
}
}
""",
variables={"cik": "63908"}
):
print(f"New submission: {data}")
finally:
await client.close()
asyncio.run(main())
Configuration
Default Endpoints
By default, the client connects to:
- Queries:
https://secparse.com/api/graphql - Subscriptions:
wss://secparse.com/api/graphql/ws
Custom Endpoints
from secparse import SecParseClient
client = SecParseClient(
api_key="your-api-key",
url="https://custom.secparse.com/api/graphql",
ws_url="wss://custom.secparse.com/api/graphql/ws"
)
Additional Headers
client = SecParseClient(
api_key="your-api-key",
headers={
"X-Custom-Header": "value"
}
)
Custom Timeout
client = SecParseClient(
api_key="your-api-key",
timeout=60.0 # 60 seconds
)
Error Handling
from secparse import SecParseClient, SecParseRequestError, SecParseConnectionError
async def main():
client = SecParseClient(api_key="your-api-key")
try:
result = await client.query("""
query {
Fact(limit: 10) {
effectiveDate
valueNumber
}
}
""")
except SecParseRequestError as e:
print(f"Request error: {e}")
print(f"GraphQL errors: {e.errors}")
print(f"Status code: {e.status_code}")
except SecParseConnectionError as e:
print(f"Connection failed: {e}")
finally:
await client.close()
Common Query Examples
Get Company Facts
query {
Fact(
where: {
Concept: {name: {_eq: "Assets"}, namespace: {_eq: "us-gaap"}}
Submission: {filerCik: {_eq: "63908"}}
isSuperseded: {_eq: false}
}
order_by: {effectiveDate: desc}
limit: 5
) {
effectiveDate
valueNumber
measure
Submission {
Filer {
name
cik
}
type
acceptedDate
}
}
}
Get Submission Details
query {
Submission(
where: {filerCik: {_eq: "63908"}}
order_by: {acceptedDate: desc}
limit: 10
) {
accessionNumber
acceptedDate
type
Filer {
name
cik
}
}
}
Publishing to PyPI
1. Install build tools
pip install build twine
2. Update package metadata
Edit pyproject.toml:
- Update
versionwhen releasing - Add your name and email in
authors - Update URLs to your repository
3. Build the package
python -m build
4. Upload to PyPI
Test on TestPyPI first:
python -m twine upload --repository testpypi dist/*
Then upload to PyPI:
python -m twine upload dist/*
5. Install your published package
pip install secparse
Development
Install development dependencies
pip install -e ".[dev]"
Run tests
pytest
Format code
black secparse
Type checking
mypy secparse
Requirements
- Python 3.8+
- httpx >= 0.24.0
- websockets >= 11.0
API Key
Get your SecParse API key from secparse.com.
License
MIT License - see LICENSE file for details.
Resources
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file secparse-0.1.0.tar.gz.
File metadata
- Download URL: secparse-0.1.0.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15d10236906e508bbdbcdd95c85909cca71f23c8dc6271e2a66773045d98dcfb
|
|
| MD5 |
0c818279e681c7f76e29ebd9e5f56156
|
|
| BLAKE2b-256 |
4e154ab994b47cb1f83bb2b9a67019ccca4f441a5ed3ddf7502b0162e2f795b3
|
File details
Details for the file secparse-0.1.0-py3-none-any.whl.
File metadata
- Download URL: secparse-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
94d0a6a0959d806a34c710534c7d7a17007571c448e3351b4228c5f1ec94b4c4
|
|
| MD5 |
6179770b0e1803127834296f4d090f5a
|
|
| BLAKE2b-256 |
2b355b2bef9e29480e9a1f0b04aa5b51d168d4c82c4c6a3cbf50cacaa9caed8d
|