Library for cryptocurrency prices and currency conversion without API keys
Project description
CryptoManager
CryptoManager is a small Python library for getting cryptocurrency and fiat exchange rates, converting between currencies, and working with simple money objects.
The library works without required API keys. It tries multiple public providers in order and falls back to the next provider when one of them is unavailable.
Installation
pip install cryptomanager
Quick Start
import cryptomanager as cm
btc_usd = cm.price(1, "BTC")
eth_eur = cm.price(1, "ETH", "EUR")
print(f"1 BTC = ${btc_usd:,.2f}")
print(f"1 ETH = EUR {eth_eur:,.2f}")
You can also use the global manager object directly:
from cryptomanager import cm
print(cm.price(0.5, "BTC"))
Conversion
import cryptomanager as cm
btc_to_usdt = cm.transfer(1, "BTC").to("USDT")
eth_to_btc = cm.transfer(10, "ETH").to("BTC")
usd_to_eur = cm.transfer(100, "USD").to("EUR")
print(btc_to_usdt)
print(eth_to_btc)
print(usd_to_eur)
Local Fixed-Rate Conversion
Use local conversion when you want to provide your own fixed rate:
import cryptomanager as cm
RUBY_RATE = 90
result = cm.transfer.local(2, "USD").to((RUBY_RATE, "RUBY"))
print(result) # 180
Money Objects
import cryptomanager as cm
usdt = cm.money("USDT")
amount = usdt(1000)
btc_amount = amount.to("BTC")
print(amount)
print(btc_amount)
Supported Providers
Crypto providers:
- Binance
- CoinGecko
- Coinbase Exchange
- CoinPaprika
- CoinLore
- MEXC
- CoinCap
- CryptoCompare
- Kraken
- Bitfinex
- Huobi
- OKX
- Bybit
- KuCoin
- Gate.io
- Gemini
- Bitstamp
- Bittrex
- CoinMarketCap, optional API key
Fiat providers:
- Frankfurter
- Exchangerate.host
- ExchangeRate-API, optional API key
- Open Exchange Rates, optional API key
- Currency Layer, optional API key
- Fixer.io, optional API key
- Alpha Vantage, optional API key
API Keys
The package works without API keys, but some optional providers can be enabled:
import cryptomanager as cm
cm.set_api_key("coinmarketcap", "your_api_key")
cm.set_api_key("alphavantage", "your_api_key")
Do not commit API keys to GitHub.
Cache
Rates are cached for 60 seconds by default.
import cryptomanager as cm
cm.set_update_interval(30)
cm.clear_cache()
Supported Currency Lists
import cryptomanager as cm
cryptos = cm.get_supported_cryptos()
fiats = cm.get_supported_fiats()
print(len(cryptos))
print(len(fiats))
Error Handling
Network APIs can fail, rate-limit requests, or temporarily return incomplete data. Wrap live price calls in try/except:
import cryptomanager as cm
try:
price = cm.price(1, "BTC")
print(price)
except ValueError as exc:
print(f"Could not get price: {exc}")
Development
Install the local project in editable mode:
python -m pip install -e .
Run smoke tests:
python tests.py
python test_examples.py
Build release files:
python -m pip install --upgrade build twine
python -m build
python -m twine check dist/*
Upload to PyPI:
python -m twine upload dist/*
Use __token__ as the username and your PyPI API token as the password.
License
MIT License. See LICENSE.
Project details
Release history Release notifications | RSS feed
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 cryptomanager-0.1.1.tar.gz.
File metadata
- Download URL: cryptomanager-0.1.1.tar.gz
- Upload date:
- Size: 15.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d9d553fe7bffe0d11e822acd4487baeec763fb47ecc0695ff51252fe7444888
|
|
| MD5 |
095905f17d58ab4e3b7049c9c863b508
|
|
| BLAKE2b-256 |
086197a08ca73204795271bfca06c66a1a353b00280fd437abe4022fac7d5b24
|
File details
Details for the file cryptomanager-0.1.1-py3-none-any.whl.
File metadata
- Download URL: cryptomanager-0.1.1-py3-none-any.whl
- Upload date:
- Size: 13.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df761b1a7efc1e5e1ab18bac261de3ec6a7586b48736bd26f1a1da33ea37393a
|
|
| MD5 |
526e3e741bc4aedbd6cc99d71eeea9e0
|
|
| BLAKE2b-256 |
b2ea7b44b2199fd870a801be0ba4a40fa4a72fbeb1dee172db016ffbf8294787
|