Rest API for CSV data in Python

696 views
Skip to first unread message

anas.ghadieh

unread,
Nov 16, 2015, 2:47:34 PM11/16/15
to US Government APIs
Hey guys! 

I am working on a project to build APIs for CSV data using Python.

Here is a what my CSV would look like:

Year  State
2008 MD
2008 AZ
2007 DE
2007 DC
2007 FL
2009 TX

Any idea on any good open source API to use? I tried GitHub but could not find what exactly I am looking for. Thanks !

Bob Simons - NOAA Federal

unread,
Nov 16, 2015, 2:58:33 PM11/16/15
to anas.ghadieh, us-govern...@googlegroups.com
Try ERDDAP.
It is Free and Open Source Software from NOAA.
It can read data from many types of tabular data sources, including CSV files.
Requests for subsets of the dataset are made via a simple RESTful API which follows the OPeNDAP standard. It is a simple subset of SQL, formatted as a RESTful request:
see the documentation at
The response can be in any of a 20+ different file formats, including an HTML table, csv file, and .json.
It has a lot of other nice features.

ERDDAP is reusable software. You can download it, install it, and be up and running today without any programming.
Information is on the left hand side at
Download and installation instructions are at


--
You received this message because you are subscribed to the Google Groups "US Government APIs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to us-government-a...@googlegroups.com.
To post to this group, send email to us-govern...@googlegroups.com.
Visit this group at http://groups.google.com/group/us-government-apis.



--
Sincerely,

Bob Simons
IT Specialist
Environmental Research Division
NOAA Southwest Fisheries Science Center
99 Pacific St., Suite 255A      (New!)
Monterey, CA 93940               (New!) 
Phone: (831)333-9878            (New!)
Fax:   (831)648-8440
Email: bob.s...@noaa.gov

The contents of this message are mine personally and
do not necessarily reflect any position of the
Government or the National Oceanic and Atmospheric Administration.
<>< <>< <>< <>< <>< <>< <>< <>< <><

Jamal Mazrui

unread,
Nov 16, 2015, 3:05:18 PM11/16/15
to anas.ghadieh, US Government APIs

The Python standard library includes a csv module:

https://docs.python.org/2/library/csv.html

 

 

Jamal Mazrui

Director, Accessibility and Innovation Initiative

Federal Communications Commission

(202) 418-0069

--

Gray Brooks

unread,
Nov 16, 2015, 11:52:45 PM11/16/15
to Jamal Mazrui, anas.ghadieh, US Government APIs
We're working on building out a program using this simple but solid tool - https://github.com/18f/autoapi.  

Gray 

------------------------------

{
  "team": "18F",
  "company": "GSA",
  "cell": "205.541.2245",
  "links": [{
    "name": "/Developer Program",
    "url": "https://pages.18f.gov/API-All-the-X"
  }, {
    "name": "US Government API listserve",
    "url": "https://bit.ly/apilistservedc"
  }]
}

Ghadieh, Anas

unread,
Nov 17, 2015, 9:08:07 AM11/17/15
to gray....@gsa.gov, Jamal Mazrui, US Government APIs

Thanks Gray! I will look into this.

 

Anas G.

Eric van Zanten

unread,
Nov 17, 2015, 10:32:27 AM11/17/15
to US Government APIs, gray....@gsa.gov, Jamal....@fcc.gov

Hey there. Non-gov't lurker on the list for a while. Gray, the autoapi thing is pretty nifty. Have you guys checked out some of the trickery that we (DataMade) did for Plenario and Illinois Sunshine? Both of those are Flask apps and there's one function in particular that we use in both places to automatically figure out if a query submitted by a user via a query string is a valid query given the structure and characteristics of the table in the database. The code in question can be found here. This leverages the introspection stuff that you get for free in SQLAlchemy.

So, for example, given a table that that has string fields "first_name", "last_name", a date field unoriginally called "date" and an integer field called "count", a user could give you a query string that looked like:

http://whatever.gov/api/table_name/?first_name__ilike=%bill%&last_name__ilike=clinton%&date__ge=2001-01-01&count_le=10

which would get translated by that function into a SQL statement that looked something like:

SELECT * FROM table_name WHERE first_name ILIKE '%bill%' AND last_name ILIKE 'clinton%' AND date >= '2001-01-01' AND count <= 10

It would also return an error to the user if they did something silly like "first_name__ge=50" which doesn't really make sense given that "first_name" is a string field.

To get a feel for this from a user's point of view, we've documented it here for Illinois Sunshine. To bring this full circle (and make it slightly more relevant to the original question ;P), there's also some code in there the will serialize responses as CSV (as a bonus, that also puts the resulting CSV(s) into a zipfile. Python makes this pretty simple (which might be the reason why there are no real pre-packaged things that do this for you; it's built in)

Anyways, hopefully this isn't too far off topic and someone finds it valuable. I'd love to hear what you guys are thinking with the autoapi tool and whether or not this kind of approach is useful to you. Let me know if you have questions about how it works.

Eric
Reply all
Reply to author
Forward
0 new messages