Skip to main content

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.



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.
  • Local Lookup Cache: Loads static lookup tables from a built-in filters.json database file, completely eliminating network requests and rate limits when resolving names to IDs.
  • Native Multi-Query Iteration: Natively accepts lists of states and commodities (e.g. commodity=["Cotton", "Tomato"], state=["Maharashtra", "Gujarat"]). The SDK sequentially downloads and combines each combination to avoid server timeouts and rate limits, returning a single merged DataFrame.
  • 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.

Metadata

Release files for agmarknet 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for agmarknet 0.2.2
File Size Uploaded Provenance Actions
agmarknet-0.2.2.tar.gz 1.1 MB Without provenance Details for agmarknet-0.2.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for agmarknet 0.2.2
File Interpreter ABI Platform Actions
agmarknet-0.2.2-py3-none-any.whl Python 3 none any Details for agmarknet-0.2.2-py3-none-any.whl

Total release size: 1.2 MB

Release files / agmarknet-0.2.2.tar.gz

Download URL agmarknet-0.2.2.tar.gz
Size 1.1 MB
Tags Source
SHA-256 checksum
How to use checksums
a62d0c973bac80f8a0eaaa9e5872067dad60dbfb03239974f1cdd0c816a27d58
BLAKE2b-256 checksum
How to use checksums
fdf65345bcf461fa0f9e45b5a279906afd60bbb9ac731bdc9c48f831996c28f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.9

Release files / agmarknet-0.2.2-py3-none-any.whl

Download URL agmarknet-0.2.2-py3-none-any.whl
Size 133.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c7ef3ca59f9a220f55d3d5c6c69620237e916285b1f942b67f58dc8ae043f42f
BLAKE2b-256 checksum
How to use checksums
fcd23c8390ee88a5594be5e91d5787a5da67365cf9a35a0e96d0b35613ef5d47
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.9

Security for agmarknet 0.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page