A while ago I was looking for an API which provided Buddhists Texts and I couldn’t finda good one – so I’ve created one myself and published it.
I’ve started with the Dhammapada which is pretty much the most well-known of the original Buddhist texts. It’s compact and is divided up nicely into chapters and verses. It’s also one of my favourites, full of lovely quotes such as
Not the sweet smell of flowers, not even the fragrance of sandal,tagara,or jasmine blows against the wind. But the fragrance of the virtuous blows against the wind. Truly the virtuous man pervades all directions with the fragrance of his virtue.
Pupphavagga: Flowers (dhp 4), translated from the Pali by Acharya Buddharakkhita. Access to Insight (https://www.accesstoinsight.org/)
The Dhammapada is part of a bigger collection of Buddhist texts called the Pali Canon – named after the Indian language it was originally written in. It is the oldest collection of Buddhist texts dated from the time of the Buddha himself.
API
The API is published at
http://palicanon.codebuckets.com.au/
and is freely available under these terms of use
You may download these files to your computer, print them out, read them, share them with your friends, copy them to your own website, translate them into other languages, and redistribute them electronically — provided that you do not charge any money for them. They are not in the public domain.
Basically, you can do what you like with the texts except sell them. I’m personally not massively troubled about anyone selling them either, but this license is from the original translators of the texts at Access to Insight.
The code is published on my git hub site here
https://github.com/timbrownls20/Pali-Canon/tree/master/Api
and is freely available to use under similar terms, again to respect the wishes of the original translators.
Example Calls
I think that the random quote function is the most useful, but the API also contains search functionality and the ability to retrieve specific chapters and/or verses e.g.
Generates a random quote from all supported texts
2. http://palicanon.codebuckets.com.au/api/quote/100
Generates a random quote from all supported texts of a maximum length of 100 characters
3. http://palicanon.codebuckets.com.au/api/sutta/dhp/4/5
Gets the fifth verse of the fourth sutta of the Dhammapada collection. This is the Flowers sutta
4. http://palicanon.codebuckets.com.au/api/search/happiness/5
Gets the first 5 quotes from all supported text which contain the word happiness
The full OpenAPI definition is available at here which can also be used to automatically generate clients using NSwagStudio or similar
Technical Details
The overall aim is to use purely open-source software for this. Therefore
- The API is coded in Asp.Net Core 3.1
- Database is MySql
- Containerised into Linux containers using Docker
- Containers deployed onto a Linux (Debian) hosted at Digital Ocean
Clients
I’ve coded several clients that use the API.
Angular – https://github.com/timbrownls20/Pali-Canon/tree/master/Client/Angular/pali-canon
React – https://github.com/timbrownls20/Pali-Canon/tree/master/Client/react.palicanon
Asp.Net Razor Pages – https://github.com/timbrownls20/Pali-Canon/tree/master/Client/RazorPages
The Razor Pages one is a good one to look at, if you are curious. That has a footer which randomly generates Dhammpada quotes which is pretty nice and a good use case for the API.
Next Steps
I’ve been through a couple of iterations of the API so I think the endpoints are pretty stable now. The next step is to put some more content in. The next ones will be
Theragatha
This is a collection of poetry written by the Buddha’s male followers – the monks. It’s very quoteable. It’s provided by Access to Insight however it’s incomplete so only part of it will go in
Therigatha
Very similar to the above except it’s poetry by Buddhist nuns. Again, very quoteable and very lovely and provided by Access to Insight. Also, incomplete.
Dhammapada – translated by F. Max Muller
One of the oldest translations of the Dhammapada. Some of the translations are a bit odd (church, sin etc…) but it’s translation that I’m very fond of. It’s freely available at the Gutenberg Project. I’ll have to extend the API at this point to include authors, but I’ve designed the API with that extension in mind.
Contributors
Most of the unpaid stuff I’ve done has been to try out new technologies and for my own personal amusement. This one, I actually think is useful. It would be amazing if anyone wanted to contribute – particularly writing code to bring in new content. All you would need to do is
- Write another class like the DhammapadaProvider for your new text
- Make sure it inherits from IProvider
- Provide the source for the import and make sure that it’s free to use under our terms i.e. we aren’t going to resell it.
- Update the tests here
And that’s it
Balanced against that, it would need to be someone who is interested in writing APIs and reading 2500-year-old Buddhist texts.
I suspect that there aren’t too many people who are at the intersection of that particular Venn diagram. It might be a set with just one member – me!
Good Day Sir, thanks for this generous contribution.
I will be using it to get a daily teaching for the texts.
One thing I noted was that this endpoint: http://palicanon.codebuckets.com.au/api/book/list
Only gave a single book – the dhamapada. Is that right?
Glad you found it useful. Unfortunately the Dhammapada is the only book supported at the moment. When I get time I intend to add more. All the best