Skip to main content

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

agmarknet-0.2.1.tar.gz (1.0 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agmarknet-0.2.1-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

Details for the file agmarknet-0.2.1.tar.gz.

File metadata

  • Download URL: agmarknet-0.2.1.tar.gz
  • Upload date:
  • Size: 1.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for agmarknet-0.2.1.tar.gz
Algorithm Hash digest
SHA256 e8f71313f7aee2207f2fc519116c2575d67f1d0e3e1207a65b77e6894b85cdc4
MD5 c1540ed5fa503e0046bcf86a62987128
BLAKE2b-256 c218f2e4ba680956c4ba34cc97ad554a397b2afea920bb58d42458b3a5a56672

See more details on using hashes here.

File details

Details for the file agmarknet-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: agmarknet-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 21.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for agmarknet-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 88a688079aeae3d87dc58df536cecc426307df42d992372a60357af32aab5a4f
MD5 d2a918c33c641370141c7e134e763eeb
BLAKE2b-256 8094d66b416c12e2471f16be8d741e782e4e7da38ad8228a8b3e9fc4052f4fbc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page