Skip to main content

Python SDK for USDA FAS Open Data API

Project description

USDA FAS Open Data SDK (Python)

A powerful, Pythonic SDK for the USDA Foreign Agricultural Service (FAS) Open Data API. This library provides easy access to vast agricultural data sets including Export Sales, Global Trade, and Production/Supply/Distribution data.

Source Data: USDA FAS Open Data

Data Sets Available

  • ESR (Export Sales Reporting): Weekly U.S. export sales of agricultural commodities.
  • GATS (Global Agricultural Trade System): U.S. Census and UN ComTrade import/export data.
  • PSD (Production, Supply and Distribution): Official USDA forecasts for world agricultural commodities.

Features

  • Auth Handling: Seamless integration with USDA FAS API keys.
  • Easy Mode: USDAFASEasyClient automatically normalizes data, replacing numeric codes (e.g., CountryCode: 2010) with readable names and descriptions (e.g., Name: Mexico, Genc: MEX).
  • Complete Coverage: Support for all endpoints defined in the official Swagger spec.
  • Type Hints: Fully typed for better IDE support.

Prerequisites

You need a USDA FAS API Key to use this SDK.

  1. Go to the USDA FAS Open Data Portal.
  2. Register or Login.
  3. Navigate to the "API Keys" section to generate your key.

Installation

pip install usda-fas-sdk

Quick Start

1. Configure Authentication

We recommend using a .env file to keep your API key secure.

Step 1: Create a file named .env in your project root:

USDA_FAS_API_KEY=your_actual_api_key_here

Step 2: Use the SDK

from usda_fas import USDAFASEasyClient
import json

# Automatically loads USDA_FAS_API_KEY from environment or .env
client = USDAFASEasyClient()

# Example: Get Normalized Export Sales Data for Wheat (Code 301) in 2024
data = client.get_esr_exports_normalized(commodity_code=301, market_year=2024)

if data:
    # Print the first enriched record
    print(json.dumps(data[0], indent=2))

Output Example:

{
  "commodityCode": 301,
  "countryCode": 5800,
  "weeklyExports": 0,
  "accumulatedExports": 0,
  "outstandingSales": 1323,
  "grossNewSales": 1323,
  "currentMYNetSales": 0,
  "currentMYTotalCommitment": 1323,
  "nextMYOutstandingSales": 0,
  "nextMYNetSales": 0,
  "unitId": 1,
  "weekEndingDate": "2023-06-01T00:00:00",
  "countryName": "KOR REP ",
  "countryDescription": "KOREA, REPUBLIC OF             ",
  "gencCode": null,
  "regionName": "OTHER ASIA AND OCEANIA        ",
  "commodityName": "Barley",
  "unitName": "Metric Tons"
}

2. Manual Configuration (Alternative)

You can also pass the key directly (not recommended for production code):

client = USDAFASEasyClient(api_key="your_api_key_string")

Advanced Usage

Accessing Raw Clients

If you prefer raw data or specific client separation, you can access the individual clients:

from usda_fas import ESRClient, GATSClient, PSDClient

esr = ESRClient() # Uses env var
raw_commodities = esr.get_esr_commodities()

Contributing

  1. Fork the repo.
  2. Install dependencies: pip install -r requirements.txt.
  3. Submit a Pull Request.

License

MIT

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

usda_fas_sdk-0.1.11.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

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

usda_fas_sdk-0.1.11-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file usda_fas_sdk-0.1.11.tar.gz.

File metadata

  • Download URL: usda_fas_sdk-0.1.11.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for usda_fas_sdk-0.1.11.tar.gz
Algorithm Hash digest
SHA256 495b5b2e867273a8b46a796a0080d3eadeb15c4a88f861d125fe4ecaa2634c86
MD5 70bc259f6c3bb282bf638d91d63c2dc6
BLAKE2b-256 ec4235009dad3678548e1af1cc4a0eb83dca2762de0394ee2a363820987a7b0a

See more details on using hashes here.

File details

Details for the file usda_fas_sdk-0.1.11-py3-none-any.whl.

File metadata

  • Download URL: usda_fas_sdk-0.1.11-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for usda_fas_sdk-0.1.11-py3-none-any.whl
Algorithm Hash digest
SHA256 befda7ca0ce5b2e1285b20a38945b536f38931b374b0fa166a588d15f671033f
MD5 28d8c2a5b01d87dbd015a9e5b1bf1c21
BLAKE2b-256 5261bfc956b4389211ceedbd12336491f20f2b83f562006bff9a8a75ec5743a0

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