Registry / data / efinance

efinance

JSON →
library0.5.8pypypi✓ verified 90d ago

efinance is a free and open-source Python library designed for quickly obtaining stock, fund, and futures data based on Eastmoney. It is actively maintained with frequent minor releases, providing convenience for personal trading system needs. The library simplifies the process of fetching historical and real-time financial market data.

pip install efinance
INSTALL
IMPORT
SIG · EFINANCE
E
efinance
datapythonv0.5.8
Install
10.7s avg
Import
2211ms
Disk
185MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v0.5.8 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 2.273s · 185.3MB
glibc
py 3.10–3.920 runs
installs and imports cleanly · install 10.7s · import 2.149s · 178MB
185MB installed
● package 185MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

efinance
✓ import efinance as ef
ef.stock
✓ import efinance as ef data = ef.stock.get_quote_history('600519')
ef.fund
✓ import efinance as ef info = ef.fund.get_base_info(['161725', '005827'])

Fetches historical daily K-line data for a specified stock and retrieves basic information for a list of funds, demonstrating common usage patterns.

import efinance as ef # Get historical daily K-line data for a stock (e.g., '600519' for Kweichow Moutai) stock_code = '600519' history_data = ef.stock.get_quote_history(stock_code) print(f"Historical data for {stock_code}:\n{history_data.head()}") # Get basic information for multiple funds (e.g., '161725', '005827') fund_codes = ['161725', '005827'] fund_info = ef.fund.get_base_info(fund_codes) print(f"Basic info for funds {fund_codes}:\n{fund_info.head()}")
Debug
Known issues
breakingThe library relies on web scraping data from Eastmoney. Changes to Eastmoney's website structure or APIs may cause `efinance` functions to break or return incorrect data without warning.
fix
Regularly update the library to the latest version. Monitor GitHub issues and releases for updates regarding data source changes. Consider implementing fallback mechanisms or data validation in your application.
affects: All versions
gotchaThe library explicitly states it is 'only for learning and exchange, and must not be used for commercial purposes' (本项目仅供学习交流使用,不得用于商业用途。). Using it for commercial applications may violate their terms or expose you to legal risks.
fix
Adhere strictly to the stated non-commercial use policy. For commercial projects, seek alternative, commercially licensed data providers.
affects: All versions
gotchaUsers may encounter rate limiting or network errors (限流或网络报错) when fetching large amounts of data or making frequent requests, as data is scraped from public sources.
fix
Implement delays between requests, use caching, or consider alternative data sources suggested by the library (e.g., TickFlow as mentioned in documentation) if persistent issues occur. Check your network connection.
affects: All versions
gotchaScraped data may not be perfectly real-time or entirely accurate. It's unsuitable for high-frequency trading or applications requiring guaranteed data integrity.
fix
Use the library for educational, research, or personal analysis where minor data delays or discrepancies are acceptable. For critical financial applications, use dedicated, reliable, and often paid, financial APIs with strong service level agreements.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'efinance'
The `efinance` library is not installed in your current Python environment or the Python interpreter cannot locate it.
fix
Install the library using pip: `pip install efinance` or `pip3 install efinance`. If using a virtual environment, ensure it's activated before installation.
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
The data returned from the Eastmoney API is not a valid JSON format, often due to an API change, rate limiting, or a temporary service outage resulting in an HTML error page or an empty response instead of expected data.
fix
Check your internet connection, try again later, or ensure your `efinance` library is updated to the latest version: `pip install --upgrade efinance`. If the issue persists, the upstream Eastmoney API might have changed its response format, requiring a library update or code adjustment.
Column name doesn't match the data that is fetched by efinance
The column names returned by `efinance` functions (e.g., `get_realtime_quotes`) have changed or differ from what your code expects, often due to updates in the underlying Eastmoney data source or the `efinance` library itself.
fix
Inspect the actual column names returned by `efinance` (e.g., by printing `df.columns` or `df.head()`) and update your code to match the new column names. For example, '开盘' (open) might have changed to '今开' (current open).
AttributeError: 'DataFrame' object has no attribute 'some_old_column_name'
This typically occurs when a function within `efinance` (or the underlying data source) changes the structure of the returned Pandas DataFrame, such as renaming or removing a column, and your code attempts to access the old, non-existent column.
fix
Review the documentation or recent changes for the `efinance` function you are using to understand the updated DataFrame structure. Adjust your code to use the correct, current column names. Consider printing `df.columns` to see available columns.
Upgrade
Version history
0.5.8latest on PyPI · released Mar 18, 2026
Audit
Dependencies
pandasrequiredUsed extensively for data structuring and manipulation, especially for returning historical and real-time quotes as DataFrames.
numpyrequiredLikely used internally for numerical operations within data processing functions.
requestsrequiredFundamental for making HTTP requests to scrape data from web sources like Eastmoney.
Agent activity
43 hits · last 30 days
node
41
OpenAI (training)
1
Resources
efinance — pip install efinance · libregistry