FyleSDK is a Python SDK for accessing Fyle APIs. It makes integration of Fyle very easy with Python Applications. It has a series of functions which can be used to access different APIs that we provide.

Here is a link to the GitHub repository:

https://github.com/fylein/fyle-sdk-py

Quickstart Tutorial -

Let’s see how FyleSDK can be used by creating a command-line application to export expenses into a CSV file.

Install FyleSDK using pip -

$ pip install fylesdk


Now create a new file quickstart.py and copy the following code -

"""

Shows basic usage of fylesdk.

Exports details of up to 100 Expenses into a CSV.

"""

import csv

from fylesdk import FyleSDK

""" Making a connection to our server with the credentials created on the web app. """

connection = FyleSDK(

   base_url='<Your Base URL>',

   client_id='<Your Client Id>',

   client_secret='<Your Client Secret',

   refresh_token='<Your Refresh Token>'

)

"""

Making calls to different APIs in the pattern:

   <FyleSDK INSTANCE>.<API_NAME>.<API_METHOD>(<PARAMETERS>)

This will get up to 100 Expenses.

"""

expenses = connection.Expenses.get(limit=100, offset=0)

""" Exporting the details to csv using DictWriter. """

with open('expenses_export.csv', 'w') as export_file:

   keys = expenses['data'][0].keys()

   dict_writer = csv.DictWriter(export_file, fieldnames=keys, delimiter=',')

   dict_writer.writeheader()

   dict_writer.writerows(expenses['data'])

Once you have copied and saved the code in a file named “quickstart.py”, run it by typing -

$ python quickstart.py


Your expenses will be exported to expenses_export.csv

Example Output:

Did this answer your question?