DEV Community

Mwenda Harun Mbaabu
Mwenda Harun Mbaabu

Posted on

Introduction to the Beyonic API and Fast API

Today we will discuss how to build a payment application with Beyonic API and Fast API, which is a modern and very fast Python framework.

Beyonic API

As i had earlier written in my previous article on Building A Payment Application using Python Flask Framework, Docker and the Beyonic API, the Beyonic API is a REST based application programming interface that lets you extend the Beyonic dashboard features into your application and systems, allowing you to build amazing payment experiences.

Getting Help

For usage, general questions, and discussions about the Beyonic API the best place to go to is Beyhive Slack Community, also feel free to clone and edit this repository to meet your project, application or system requirements.

To start using the Beyonic Python API, you need to start by downloading the Beyonic API official Python client library and setting your secret key.

Fast API

FastAPI is a Python web framework that has been built from the ground up to make use of modern Python features. It uses the ASGI standard for asynchronous, concurrent connectivity with clients, and it can work with WSGI if needed. Async functions can be used for routes and endpoints. And FastAPI allows web applications to be written efficiently in clean, modern Python code with type hints.

As the name implies, a primary use case of FastAPI is building API endpoints. This you can accomplish as easily as returning Python dictionary data as JSON, or by using the OpenAPI standard including an interactive Swagger UI. But FastAPI is by no means limited to APIs. You can use it for just about everything else a web framework does, from delivering plain old web pages using the Jinja2 template engine to serving applications powered by WebSockets.

Set up your development environment

To learn how to securely set up a development environment visit this repository where i have discussed to use .env file to secure your API key.

>>> pip install python-dotenv

>>> pip install beyonic

>>> pip install fastapi   

>>>  pip install "uvicorn[standard]"
Enter fullscreen mode Exit fullscreen mode
#.env file 
BEYONIC_ACCESS_KEY = "enter your API " 
Enter fullscreen mode Exit fullscreen mode

You will get your API Token by clicking your user name on the bottom left of the left sidebar menu in the Beyonic web portal and selecting ‘Manage my account’ from the dropdown menu. The API Token is shown at the very bottom of the page.

#app.py file 
import os 
import beyonic
from fastapi import FastAPI
from dotenv import load_dotenv 

load_dotenv()

app = FastAPI()

myapi = os.environ['BEYONIC_ACCESS_KEY']

beyonic.api_key = myapi  


@app.get("/contacts")
def contacts():
    mycontacts = beyonic.Contact.list() 
    return mycontacts  

Enter fullscreen mode Exit fullscreen mode

Running your Application:

uvicorn main:app --reload
Enter fullscreen mode Exit fullscreen mode

Now open this url 👉🏻 http://127.0.0.1:8000/docs on your local machine and you should see the following output in your browser.
Image description

Finally click on the contacts path then try out open and execute, if your programs runs successfully you will see the following output on your browser.

Image description

Congratulations, you have successfully listed all the contacts you have in the beyonic account, you can go on and write more complex functions which allows one to send money, receive money or request money from someone who owes using the beyonic API and .

You can check out the full MFS Africa developers documentation 👉🏻 https://developers.mfsafrica.com/, to learn more about the beyonic API, or join and network with fellow developers building inspiring services with the beyonic APIs 👉🏻 https://beyonic.com/join-community .

Top comments (0)