Skip to main content

Currency Converter Script

A lightweight Python tool that performs currency conversions using daily updated exchange rates. It fetches data from the open-source currency API developed by Fawaz Ahmed via the jsDelivr CDN.

Financial Disclaimer: This script uses daily cached exchange rates. It does not update in real-time and is not suitable for live financial trading or transactional environments.


Features

  • Daily Rates: Automatically fetches exchange rates matching your system's current date.
  • Format Ready: Outputs currency values as clean, comma-separated strings rounded to 2 decimal places.
  • Error Handling: Built-in protection against invalid or unavailable currency codes.
  • Case Insensitive: Accepts both uppercase and lowercase currency codes (e.g., CAD, cad, Cad).

🛠️ Prerequisites & Tech Stack

  • Language: Python 3.12 or later
  • Libraries: requests (external HTTP library)

Install Dependencies

Before running the script, ensure you have the requests library installed:

pip install requests

Usage & API Reference

current_rates(amount, input_currency, output_currency)

Fetches the exchange rate for the current date and returns a formatted conversion string.

Parameters

  • amount (float | int): The numerical value of the currency you want to convert.
  • input_currency (str): The 3-letter ISO code for the base currency (e.g., "cad").
  • output_currency (str): The 3-letter ISO code for the target currency (e.g., "jpy").

Return Value

  • Returns a formatted str representing the converted amount (e.g., "10,450.50"), or an error message string ("Currency not available").

Quickstart Examples

You can import and run the function directly in your Python workflow:

# Example 1: Converting a whole number (100 CAD to JPY)
result_1 = current_rates(100, "cad", "jpy")
# Output: Prints and returns the converted formatted string

# Example 2: Converting a precise decimal number (540.65 CAD to JPY)
result_2 = current_rates(540.65, "CAD", "JPY")

Limitations & Data Sources

  • No Real-Time Tracking: Rates are updated once per day by the data provider.
  • System Clock Dependency: The script relies on datetime.date.today(). Ensure your system time is accurate to pull the correct daily file.
  • Data Provider: Powered by the @fawazahmed0/currency-api.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

currency_convert-0.1.0.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

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

currency_convert-0.1.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file currency_convert-0.1.0.tar.gz.

File metadata

  • Download URL: currency_convert-0.1.0.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for currency_convert-0.1.0.tar.gz
Algorithm Hash digest
SHA256 17c2a015098270cc6863aac5b5781ddb816c6c4384e28fa3f1917a5d85d894b8
MD5 6a29ffab60182cdfc741cbabe4c70555
BLAKE2b-256 5e0eabd1d307e2d501efd1b5713721fc1bd3212936cf741b659dc3defa2f7dd5

See more details on using hashes here.

File details

Details for the file currency_convert-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: currency_convert-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for currency_convert-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3e9548bd4bb6db2841777de61a943c234d7dd27638f7a66fc41008e563e16d8b
MD5 214e3728d0a6dae0818ac9fae3a7f16c
BLAKE2b-256 87e05d986c3fc162508f2108e11d31fc846d3fb9fd70a8d248ea94320fa917d6

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