Pythonic pandas wrapper for the official AGMARKNET REST API.
Project description
agmarknet (Unofficial Python SDK)
A Pythonic client and pandas wrapper for the official AGMARKNET REST API. This library enables research analysts, developers, and data scientists to easily query market prices and arrivals data directly into pandas DataFrames without scraping HTML.
[!IMPORTANT] Unofficial Implementation & Compliance Disclaimer
This is an unofficial Python SDK. It is not developed, endorsed, or supported by the Government of India.
By using this library, you agree to comply with the official website policies of AGMARKNET:
- Source Policy: The official AGMARKNET portal is maintained by the Directorate of Marketing & Inspection (DMI), Department of Agriculture & Farmers Welfare, Ministry of Agriculture & Farmers Welfare, Government of India. The portal provides timely and reliable information to farmers, traders, consumers, researchers, and other stakeholders.
- Copyright Policy: Information fetched from AGMARKNET may be reproduced free of charge, provided the material is reproduced accurately, not used in a derogatory or misleading context, and the source is acknowledged as https://agmarknet.gov.in.
- Terms & Conditions & Legal Purpose: The data fetched by this library should not be used for legal purposes. The Directorate of Marketing & Inspection (DMI) and the developers of this SDK are not liable for any loss arising from the use of this information. These terms are governed by Indian law, and any disputes will fall under Indian jurisdiction.
- Disclaimer of Authenticity: Market prices and arrival data are reported and shared by the respective APMC/Markets. Users are advised to exercise their discretion and judgment before making decisions using this data. The Department/DMI shall not be responsible for any errors or the authenticity of the data.
Features
- Automated Name Resolution: Query using friendly name strings (e.g. state
"Karnataka", commodity"Tomato", market"Bangarpet APMC"). The SDK resolves names to official AGMARKNET IDs under the hood using exact, case-insensitive, and fuzzy matching. - Support for Price & Arrival Quantity/Units: Fetch comprehensive daily reports including prices and arrival quantities.
- Historical Chunking: Seamlessly query long date ranges (e.g., since 2007). The SDK automatically splits request windows into yearly chunks to circumvent backend limitations, de-duplicates rows, and sorts the result chronologically.
- Pagination Handling: Transparently fetches all pages from the paginated backend API and merges them into a single pandas DataFrame.
- Requests Session Configuration: Configures timeouts, retries, and headers out-of-the-box.
Installation
pip install agmarknet
Usage Guide
1. Initialization
from agmarknet import Agmarknet
# Create an instance of the AGMARKNET client
api = Agmarknet()
2. Fetching Daily Price and Arrival Reports
By default, the SDK requests both price and arrival data (data_type="both"). This ensures you get prices (min, max, modal) as well as arrival volumes and unit names.
df = api.report(
from_date="2026-06-01",
to_date="2026-06-05",
commodity="Tomato",
state="Karnataka",
district="Kolar", # Optional
market="Bangarpet APMC" # Optional
)
print(df.head())
Returned Columns
When using data_type="both" (default), the returned DataFrame includes the following fields:
arrival_date: The date of the record.state_name&district_name&market_name: Geographical identifiers.cmdt_grp_name&cmdt_name&variety_name&grade_name: Commodity details.min_price&max_price&model_price: Price metrics.unit_name_price: Currency/Weight unit (e.g.Rs./Quintal).arrival_qty: Volume of commodity arrival.unit_name_arrival: Arrival weight unit (e.g.Metric Tonnes).
3. Choosing a Report Type
You can customize the fetched columns by passing the data_type parameter:
both(default): Fetches both prices and arrival volumes.price: Fetches only price-related fields.arrival: Fetches only arrival-related fields (date, quantity, units).
# Fetch price only
price_df = api.report(
from_date="2026-06-01",
to_date="2026-06-05",
commodity="Tomato",
state="Karnataka",
data_type="price"
)
4. Fetching Long Historical Datasets
The backend API restricts very large queries. To fetch years of historical data, use the start and end parameters. The SDK automatically partitions the request by calendar year, manages page-by-page downloads, and compiles the result:
historical_df = api.report(
start="2015-01-01",
end="2026-07-01",
commodity="Tomato",
state="Karnataka",
district="Kolar",
market="Bangarpet APMC",
progress=True # Displays download progress in stdout/stderr
)
5. Accessing Metadata & Filters
You can inspect the underlying tables used for name-to-ID resolution:
filters = api.filters()
# Access commodity metadata
print(filters.commodities.head())
# Access states metadata
print(filters.states.head())
# Access markets metadata
print(filters.markets.head())
License & Attribution
Distributed under the MIT License. Data is provided by the Directorate of Marketing & Inspection, Government of India. Always acknowledge https://agmarknet.gov.in when using or sharing data generated by this tool.
Project details
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 agmarknet-0.2.0.tar.gz.
File metadata
- Download URL: agmarknet-0.2.0.tar.gz
- Upload date:
- Size: 995.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
08a1761de4961bad73d685bcb936d1fe6a0cf0b0fd63852e6e0f088a0a9202e2
|
|
| MD5 |
80d5ccf7fc0f71eadb878683e9c141f7
|
|
| BLAKE2b-256 |
c4078f47b49315a23fc8a59b3b1706513d1c37acf8b414cf75d35ea32d40392f
|
File details
Details for the file agmarknet-0.2.0-py3-none-any.whl.
File metadata
- Download URL: agmarknet-0.2.0-py3-none-any.whl
- Upload date:
- Size: 21.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fa7e9f1fdc44aa594fe5f876bc8de1c94e7843a14e124ed2c3188f3432b60abb
|
|
| MD5 |
3dc10202d0424161ec669b44f218f79b
|
|
| BLAKE2b-256 |
2058c8c778aa9562e0c70f952be668e4f79806371ddfc0952a3f6a9ba9855264
|