Introduction to the Beyonic API and Fast API
Tags: python, 100daysofcode, payment, beyonicapi
Published: 2022-02-07 11:28:44

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](https://dev.to/luxacademy/building-a-payment-application-using-python-flask-framework-docker-and-and-the-beyonic-api-2284), 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](https://beyonic.com/join-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](https://github.com/HarunMbaabu/BeyonicAPI-Python-Examples) repository where i have discussed to use .env file to secure your API key. 


```bash 
>>> pip install python-dotenv

>>> pip install beyonic

>>> pip install fastapi   

>>>  pip install "uvicorn[standard]"
```

```python 
#.env file 
BEYONIC_ACCESS_KEY = "enter your API " 
```
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.

```python
#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  

``` 

Running your Application:

```terminal 
uvicorn main:app --reload
```

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/we3aldcej97d2w1yhbpj.png)

 
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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cedviae1ki3go1ayst7g.png)
 

**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 .