Skip to content

codeofandrin/apininjas.py

Repository files navigation

apininjas.py

An easy-to-use and async-ready Python wrapper for the API-Ninjas APIs.

PyPi version Python version License

Key Features

  • Pythonic and modern API
  • Asynchronous using async and await
  • Fully type-hinted
  • Easy to use with an object oriented design

Installing

Python 3.9 or higher is required

To install the latest stable version, use

pip install -U apininjas.py

To install the development version (may be unstable), use

pip install -U git+https://github.com/codeofandrin/apininjas.py

Example

import asyncio
from apininjas import Client

async def main():
    client = Client("api_key")

    stock = await client.fetch_stock("AAPL")
    print(f"{stock.name} is trading at ${stock.price}")

    await client.close()

if __name__ == "__main__":
    asyncio.run(main())

Example with Context Manager

Or use the context manager, which automatically cleans up.

import asyncio
from apininjas import Client

async def main():
    async with Client("api_key") as client:
        stock = await client.fetch_stock("AAPL")
        print(f"{stock.name} is trading at ${stock.price}")

if __name__ == "__main__":
    asyncio.run(main())

Links