Unofficial Python client for Avanza's API with a yfinance-style interface for stocks, ETFs, and funds
Project description
Unofficial Avanza API Client
A simple Python client for Avanza's unofficial API with a yfinance-style interface.
Features
- 📊 yfinance-style API - Familiar interface for stock/fund data
- 🔍 Search stocks, ETFs, and funds by name
- 📈 Historical price data with flexible time periods
- 💰 Recent stock price and NAV for funds
- 🔄 Automatic cache with configurable TTL
Installation
pip install python-avanza
Quick Start
import avanza
# Get stock data
stock = avanza.Stock("5361") # Avanza Bank Holding
stock.info['name']
stock.price
# Get historical data
history = stock.history("one_month")
# Get dividends
dividends = stock.dividend
Finding orderbook_id:
- Search:
avanza.search("company name") - Avanza URL:
https://www.avanza.se/aktier/om-aktien.html/5361/...→ ID is5361
Search for Instruments
# Search for stocks
results = avanza.search("volvo", instrument_type="stock", limit=5)
for hit in results['hits']:
hit['instrument']['name'], hit['instrument']['id']
# Search for ETFs
results = avanza.search("ishares", instrument_type="etf")
# Search for funds
results = avanza.search("avanza", instrument_type="fund")
Fund Data
# Create a fund ticker
fund = avanza.Fund("41567")
# Get fund info
fund.info['name']
fund.price['nav']
# Historical data
history = fund.history("one_year")
Cache Management
# Default: 60 second cache
stock = avanza.Stock("5361")
# No caching (always fresh)
stock = avanza.Stock("5361", cache_ttl=0)
# Custom cache duration (5 minutes)
stock = avanza.Stock("5361", cache_ttl=300)
# Manual refresh
stock.refresh() # Clear cached data
Time Periods
# Use strings
stock.history("one_week")
stock.history("one_month")
stock.history("one_year")
# Or use enum
stock.history(avanza.TimePeriod.ONE_WEEK)
Available periods: today, one_week, one_month, three_months, this_year, one_year, three_years, five_years, infinity
Examples
See example.py for complete working examples.
Contributing
Setup:
# Clone and install
git clone https://github.com/de-ping/avanza.git
cd avanza
pip install -e ".[dev]"
Development:
# Run tests
pytest
# Format code
black avanza/ tests/
# Lint
flake8 avanza/ tests/ --max-line-length=120
Pull Requests:
- Ensure tests pass
- Format code with Black
- Add tests for new features
⚠️ Disclaimer
This project is an unofficial Python client for Avanza.
- It uses undocumented and unofficial APIs
- It is not affiliated with, endorsed by, or supported by Avanza
- API behavior may change or stop working at any time
- Use of this library may violate Avanza’s terms of service
This project is intended primarily for educational and experimental purposes, such as learning about HTTP APIs and Python library design.
Usage risks
Because this client relies on unofficial endpoints:
- Requests may be rate limited
- Accounts or IP addresses may be temporarily or permanently blocked
- Functionality may break without notice
Use at your own discretion and risk.
If you need reliable or supported access to Avanza services, please use Avanza’s official website or applications, or contact Avanza directly regarding official API access.
Legal
This software is provided “as is”, without warranty of any kind. The author assumes no liability for any damages or losses resulting from its use. Users are responsible for ensuring their usage complies with all applicable laws and terms of service.
License
MIT License - See LICENSE file for details
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 python_avanza-0.1.0.tar.gz.
File metadata
- Download URL: python_avanza-0.1.0.tar.gz
- Upload date:
- Size: 15.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
378b20878c1141cc15af65fa419ccda22620ae95928e41e93e47674bdebfcb7e
|
|
| MD5 |
ed8774813dd15c9780a08f660406a147
|
|
| BLAKE2b-256 |
560b06d5cb14f732e23cdb7ec4dc5a94c834ebf7f75e8aa428e75461ec6ba6b1
|
File details
Details for the file python_avanza-0.1.0-py3-none-any.whl.
File metadata
- Download URL: python_avanza-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4acb36a9e792dac31f687a2a18006d03c5c510bc0830ad25c4c5489adac97510
|
|
| MD5 |
f67a16e03c4678a7b9f2de6918113e51
|
|
| BLAKE2b-256 |
f7e6633767903452b5a92406478986b70869810aae5fc852b4bccda04c8afd86
|