APIprovides access to the structured data underlying this site. It requires a certain level of technical knowledge to use it, but if you've got the know-how, you can use it to quickly build your own tools using Parliamentary data.
URL structures mirror that of the main site, but on the
api.openparliament.ca domain. Most pages will have a JSON link in the footer leading to the equivalent API content.
Everything is JSON. But, when you access the page in your browser (or, specifically, with a client whose
Accept header indicates a preference for
application/json), you'll get a friendly formatted page instead. Here, take a look.
It’s hypertext. Most resources link to related resources. Start with bills, votes, MPs, debates, or committees, and you should be able to find your way to what you're looking for. Resources are identified by their URLs, which are of course guaranteed to be unique; if you need a field to use as a primary key for objects, I suggest the URL or a fragment of it. When filtering based on a relationship with another object, you use the URL, like so.
Many resources can be filtered. The list of available filters appears on each resource’s friendly API page. You can use simple operators for most numeric and date fields: gt (greater than), gte (greater than or equal), lt (less than), lte (can you guess?). Here's an example.
There’s a rate limit. If you make tons of concurrent requests, you'll get
HTTP 429 Too Many Requests. Get in touch if this is a problem for you.
Things change. I'm not yet making an ironclad backwards-compatibility promise. If you’re using this, you should sign up for a low-traffic mailing list where I’ll post about any breaking changes. To indicate that you're expecting responses that match the current version of the API, set a
API-Version header to
v1, or include
?version=v1 in your query string. Responses will include an
API-Version header with the version of the response.
Don’t be shy. The API doesn’t currently enforce this, but you should put your email in
User-Agent headers—that way I can look at how people are using the API, and contact you if your requests are causing problems. And please get in touch with comments and questions.
This kind of API is not especially suited to downloading lots of data at once. For that, download a copy of this site's database.
To find ridings or MPs based on addresses or postal codes, use Represent.
parl.gc.ca has, in recent years, started to include lots of XML data—that's the original source for 90% of the data on this site. Hansard and LegisINFO pages will have little orange XML buttons on them.
The LIPAD project contains structured digital versions of Hansard since 1900.
This site holds no copyright on any data accessible through this API. But providing attribution via a link back to openparliament.ca would be awfully nice of you.
Freedom to tinker
The code behind this site is available on GitHub, as free software. It's in Python, mostly.