Open Bug 990765 Opened 10 years ago Updated 3 years ago

Python module for native REST API

Categories

(Bugzilla :: Bugzilla-General, enhancement)

enhancement
Not set
normal

Tracking

()

People

(Reporter: mcote, Unassigned)

References

(Blocks 1 open bug)

Details

Several people have inquired about having a Python module to conveniently access the native API.

There are many approaches that one might take; a good starting point would be to extend the existing XMLRPC-based client, https://fedorahosted.org/python-bugzilla/, or at least use it as a starting point.
Blocks: 1003236
See Also: → 774141
I don't see why this should be part of Bugzilla. Bugzilla is a Perl application. Unless you plan to release it separately, outside the Bugzilla tarball?
I am interested in this Bug. However I am new to Bugzilla I dont know how to take on and start on the bug. Please direct me the way so I can do this.
There are already many external projects working on this, see:

https://github.com/AutomatedTester/Bugsy
http://k0s.org/toolbox/?usage=bugzilla&language=python

See bug 774141 for more discussion about it.

I personally think that this has nothing to do as part of Bugzilla itself, but is a whole separate project. IMO, a better approach would be to contribute to existing projects than to reinvent the wheel. Note that this is just my opinion.
Severity: normal → enhancement

Hi,
use the below code,maybe this would be useful for your issue -

from flask import Flask, request
from flask_restful import Resource, Api
from sqlalchemy import create_engine
from json import dumps
from flask.ext.jsonpify import jsonify

db_connect = create_engine('sqlite:///chinook.db')
app = Flask(name)
api = Api(app)

class Employees(Resource):
def get(self):
conn = db_connect.connect() # connect to database
query = conn.execute("select * from employees") # This line performs query and returns json result
return {'employees': [i[0] for i in query.cursor.fetchall()]} # Fetches first column that is Employee ID

class Tracks(Resource):
def get(self):
conn = db_connect.connect()
query = conn.execute("select trackid, name, composer, unitprice from tracks;")
result = {'data': [dict(zip(tuple (query.keys()) ,i)) for i in query.cursor]}
return jsonify(result)

class Employees_Name(Resource):
def get(self, employee_id):
conn = db_connect.connect()
query = conn.execute("select * from employees where EmployeeId =%d " %int(employee_id))
result = {'data': [dict(zip(tuple (query.keys()) ,i)) for i in query.cursor]}
return jsonify(result)

api.add_resource(Employees, '/employees') # Route_1
api.add_resource(Tracks, '/tracks') # Route_2
api.add_resource(Employees_Name, '/employees/<employee_id>') # Route_3

if name == 'main':
app.run(port='5002')

There will be three routes created :

http://127.0.0.1:5002/employees shows ids of all the employees in database
Screen Shot 2017-02-13 at 11.43.30.png
http://127.0.0.1:5002/tracks shows tracks details
Screen Shot 2017-02-13 at 11.43.42.png
http://127.0.0.1:5002/employees/8 shows details of employee whose employeeid is 8
Screen Shot 2017-02-13 at 11.43.52.png
It is simple to create a API. You can also add support to PUT,POST and DELETE on data too.
GitHub link is given below. Fork, Clone and add the supports and ace me back the Pull Requests

Regards - https://www.sevenmentor.com/best-python-classes-in-pune.php

You need to log in before you can comment on or make changes to this bug.