feat(async): add asynchronous CoinGeckoAPI implementation#92
Open
arielen wants to merge 2 commits intoman-c:developfrom
Open
feat(async): add asynchronous CoinGeckoAPI implementation#92arielen wants to merge 2 commits intoman-c:developfrom
arielen wants to merge 2 commits intoman-c:developfrom
Conversation
- Updated func_args_preprocessing decorator in utils.py to support async methods. - Implemented AsyncCoinGeckoAPI class with asynchronous functionality mirroring CoinGeckoAPI. - Added mock tests for all AsyncCoinGeckoAPI methods. - Imported AsyncCoinGeckoAPI in __init__.py.
Contributor
Author
Usage Exampleimport asyncio
from pycoingecko import AsyncCoinGeckoAPI
async def main():
# Using the AsyncCoinGeckoAPI class via an async context manager
# You can also initialize the key here
async with AsyncCoinGeckoAPI() as api:
price_data = await api.get_price(ids="bitcoin", vs_currencies="usd")
print("Price data:", price_data)
coins_category = await api.get_coins_categories()
print("Coins categories:", coins_category)
# Alternatively, using the create() method:
obj_api = await AsyncCoinGeckoAPI.create()
price_data = await obj_api.get_price(ids="bitcoin", vs_currencies="usd")
print("Price data using create():", price_data)
await obj_api.close()
if __name__ == "__main__":
asyncio.run(main())Explanation
@man-c, always happy to interact and thanks for the review and further merge ! |
- Added dependencies: `aiohttp`, `aiohttp_retry`, and `orjson` in setup.py. - Replaced `json` with `orjson` in api.py for better performance in CoinGeckoAPI. - Updated README.md to include instructions for installing test dependencies.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changelog:
func_args_preprocessingdecorator inutils.pyto support async methods.AsyncCoinGeckoAPIclass with asynchronous functionality mirroringCoinGeckoAPI.AsyncCoinGeckoAPImethods.AsyncCoinGeckoAPIin__init__.py.aiohttp,aiohttp_retry, andorjsoninsetup.py.jsonwithorjsonin api.py for better performance in CoinGeckoAPI.BREAKING CHANGE:
pytest-asyncioandaioresponses.AsyncCoinGeckoAPIdepends onorjsonandaiohttp;orjsonis significantly faster than the standardjsonmodule and should be considered for replacing it throughoutCoinGeckoAPI.