REST API for Your Repository


This Page Is for an Old Version of

Some of the information may be out of date. If you have questions, please get in touch at [email protected]

If you plan on providing access to your repository in a more structured way to clients, one of the ways to consider is making a custom REST API directly to your repository. Although this requires a little more work than directly connecting to repository via's API, it offers you a lot of power in setup.

I'm going to build this REST API in Python 3, Flask and Flask-RESTful. However, our reference documentation covers how to connect to using cURL, Ruby, Node, and PHP, so feel free to follow along in the language/technology of your choice.

First, I'm going to get started by creating a new repository on, with some sample sales data from Kaggle.


Next, create a new file on your computer. This will hold our server's code. Making sure you have Flask and Flask-RESTful installed, use the following boilerplate code:

from flask import Flask
from flask_restful import Resource, Api

app = Flask(__name__)
api = Api(app)

class HelloWorld(Resource):
    def get(self):
        return {'hello': 'world'}

api.add_resource(HelloWorld, '/')

if __name__ == '__main__':

Running python should start running a server (make sure you are using the right version of Python):

bitio-demo ➤ python3                                                                            
 * Serving Flask app 'server' (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Running on (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 451-073-227

Great! If we make a cURL request to the server, you should be able to see the hello world output:

bitio-demo ➤ curl ""                                  
    "hello": "world"

Now to connect to our repository. Lets download the Python SDK from pip install bitdotio. The docs for the Python SDK are here (Note that you need PostgreSQL downloaded for the install to work). Let's snag the API key from the Connect button on our repo:


And we can connect to the repo from our server using just a few lines.

import bitdotio

# Connect to
b = bitdotio.bitdotio("<YOUR_API_KEY>")

Let's create a new endpoint to return the count of records in our repo (and remove our HelloWorld endpoint). Now our code looks like this:

from flask import Flask
from flask_restful import Resource, Api

import bitdotio

# Connect to
b = bitdotio.bitdotio("<API_KEY>")

app = Flask(__name__)
api = Api(app)

class Count(Resource):
    def get(self):
        conn = b.get_connection()
        cur = conn.cursor()
        cur.execute('SELECT count(*) FROM "tk-bitio/Sales"."sales_data_sample";')
        return cur.fetchone()

api.add_resource(Count, '/count')

if __name__ == '__main__':

And sure enough, if we make a request to /count, we get:

bitio-demo ➤ curl ""                             

and that's it! We've created a Flask server to serve resources of your repository. You can add fields, remove fields, or restrict access to your repo in a very controlled way using this approach.

What did you think of this blog post? Was it helpful and/or was something confusing? Please let us know in the Discussions tab!