SDKs overview
Open Disease offers a suite of official and community-maintained Software Development Kits (SDKs) and libraries designed to facilitate interaction with its public API. These SDKs are available across multiple programming languages, abstracting the underlying HTTP requests and response parsing, which can streamline the integration of disease data into various applications. The Open Disease API provides access to real-time and historical statistics for COVID-19 and other infectious diseases globally and by country, along with disease-related news feeds Open Disease API documentation. Since the API is public and does not require authentication, the SDKs primarily focus on simplifying endpoint access and data handling.
Developers can choose an SDK that aligns with their preferred programming language, allowing for more idiomatic code and reduced development time. The official SDKs are typically maintained by the Open Disease project, while community libraries are independently developed and may offer different features or approaches to API interaction. Understanding the available SDKs and their respective installation methods is critical for efficient data integration.
Official SDKs by language
Open Disease provides official SDKs for several popular programming languages, ensuring direct and supported access to its API endpoints. These SDKs are developed and maintained by the Open Disease project to provide a consistent and reliable interface. The table below outlines the primary official SDKs, their package names, installation commands, and general maturity status.
| Language | Package Name | Installation Command | Maturity |
|---|---|---|---|
| JavaScript | diseases-sh |
npm install diseases-sh or yarn add diseases-sh |
Stable |
| Python | diseases-sh-py |
pip install diseases-sh-py |
Stable |
| PHP | diseases-sh/php-sdk |
composer require diseases-sh/php-sdk |
Stable |
| Go | github.com/diseases-sh/go-sdk |
go get github.com/diseases-sh/go-sdk |
Stable |
| Ruby | diseases-sh-ruby |
gem install diseases-sh-ruby |
Stable |
| Java | diseases-sh-java |
Maven: Add dependency; Gradle: Add dependency | Stable |
Each official SDK is designed to reflect the structure of the Open Disease API endpoints, offering methods that correspond to various data retrieval operations, such as fetching global COVID-19 statistics, country-specific data, or historical trends. Developers are encouraged to consult the specific documentation for each SDK to understand its full capabilities and usage patterns.
Installation
Installing an Open Disease SDK typically follows standard package management practices for each respective programming language. Below are detailed instructions for the most commonly used languages.
JavaScript (Node.js/npm)
For JavaScript environments, the diseases-sh package can be installed using npm or Yarn:
npm install diseases-sh
# or
yarn add diseases-sh
After installation, you can import the library into your project:
import { getGlobalCovidStats } from 'diseases-sh';
// Or for CommonJS
// const { getGlobalCovidStats } = require('diseases-sh');
Python (pip)
The Python SDK, diseases-sh-py, is available via pip:
pip install diseases-sh-py
To use it in your Python script:
from diseases_sh import DiseaseAPI
api = DiseaseAPI()
PHP (Composer)
The PHP SDK can be installed using Composer, the dependency manager for PHP:
composer require diseases-sh/php-sdk
Ensure your project includes Composer's autoloader:
<?php
require 'vendor/autoload.php';
use DiseasesSH\Client;
$client = new Client();
?>
Go (go get)
For Go projects, the SDK can be fetched using go get:
go get github.com/diseases-sh/go-sdk
Then, import and use it in your Go application:
package main
import (
"fmt"
"github.com/diseases-sh/go-sdk"
)
func main() {
client := diseases_sh.NewClient()
}
Ruby (Bundler/gem)
The Ruby SDK, diseases-sh-ruby, can be installed via RubyGems:
gem install diseases-sh-ruby
If you're using Bundler, add it to your Gemfile:
# Gemfile
gem 'diseases-sh-ruby'
Then run bundle install and require it:
require 'diseases-sh-ruby'
client = DiseasesSh::Client.new
Java (Maven/Gradle)
For Java developers, the diseases-sh-java SDK can be integrated using Maven or Gradle. For Maven, add the following to your pom.xml:
<dependency>
<groupId>sh.diseases</groupId>
<artifactId>diseases-sh-java</artifactId>
<version>1.0.0</version> <!-- Use the latest version -->
</dependency>
For Gradle, add this to your build.gradle:
implementation 'sh.diseases:diseases-sh-java:1.0.0' // Use the latest version
Then, initialize the client in your Java code:
import sh.diseases.client.DiseaseClient;
public class Main {
public static void main(String[] args) {
DiseaseClient client = new DiseaseClient();
}
}
Always check the official Open Disease documentation for the latest version numbers and detailed installation instructions.
Quickstart example
The following quickstart examples demonstrate how to fetch global COVID-19 statistics using the official SDKs in various languages. These snippets illustrate the basic usage pattern: initializing the client and calling a method to retrieve data.
JavaScript
import { getGlobalCovidStats } from 'diseases-sh';
async function fetchGlobalStats() {
try {
const stats = await getGlobalCovidStats();
console.log('Global COVID-19 Stats:', stats);
console.log('Total Cases:', stats.cases);
console.log('Total Deaths:', stats.deaths);
} catch (error) {
console.error('Error fetching global stats:', error);
}
}
fetchGlobalStats();
Python
from diseases_sh import DiseaseAPI
def fetch_global_stats():
api = DiseaseAPI()
try:
stats = api.get_global_covid_stats()
print('Global COVID-19 Stats:', stats)
print('Total Cases:', stats['cases'])
print('Total Deaths:', stats['deaths'])
except Exception as e:
print(f'Error fetching global stats: {e}')
if __name__ == '__main__':
fetch_global_stats()
PHP
<?php
require 'vendor/autoload.php';
use DiseasesSH\Client;
function fetchGlobalStats() {
$client = new Client();
try {
$stats = $client->getGlobalCovidStats();
echo 'Global COVID-19 Stats: ' . json_encode($stats, JSON_PRETTY_PRINT) . "\n";
echo 'Total Cases: ' . $stats['cases'] . "\n";
echo 'Total Deaths: ' . $stats['deaths'] . "\n";
} catch (Exception $e) {
echo 'Error fetching global stats: ' . $e->getMessage() . "\n";
}
}
fetchGlobalStats();
?>
Go
package main
import (
"fmt"
"log"
"github.com/diseases-sh/go-sdk"
)
func main() {
client := diseases_sh.NewClient()
stats, err := client.GetGlobalCovidStats()
if err != nil {
log.Fatalf("Error fetching global stats: %v", err)
}
fmt.Printf("Global COVID-19 Stats: %+v\n", stats)
fmt.Printf("Total Cases: %d\n", stats.Cases)
fmt.Printf("Total Deaths: %d\n", stats.Deaths)
}
Ruby
require 'diseases-sh-ruby'
def fetch_global_stats
client = DiseasesSh::Client.new
begin
stats = client.get_global_covid_stats
puts "Global COVID-19 Stats: #{stats}"
puts "Total Cases: #{stats['cases']}"
puts "Total Deaths: #{stats['deaths']}"
rescue StandardError => e
puts "Error fetching global stats: #{e.message}"
end
end
fetch_global_stats
Java
import sh.diseases.client.DiseaseClient;
import sh.diseases.models.GlobalCovidStats;
public class Quickstart {
public static void main(String[] args) {
DiseaseClient client = new DiseaseClient();
try {
GlobalCovidStats stats = client.getGlobalCovidStats();
System.out.println("Global COVID-19 Stats: " + stats);
System.out.println("Total Cases: " + stats.getCases());
System.out.println("Total Deaths: " + stats.getDeaths());
} catch (Exception e) {
System.err.println("Error fetching global stats: " + e.getMessage());
}
}
}
Community libraries
Beyond the officially supported SDKs, the Open Disease API's public and unauthenticated nature has fostered the development of various community-contributed libraries and wrappers. These libraries are typically found on platforms like GitHub and can offer alternative implementations, additional utility functions, or support for languages not covered by official SDKs. While community libraries can be valuable, developers should exercise due diligence by checking their maintenance status, documentation, and community support before integrating them into production environments.
For example, developers may find libraries that focus on specific data visualization needs or integrate with particular web frameworks. While Open Disease does not officially endorse or maintain these, they can be discovered through searches on GitHub or package repositories for languages like Python's PyPI, Node.js's npm, or RubyGems. The Mozilla Developer Network's HTTP overview provides a foundational understanding of the underlying protocol these libraries abstract, which can be useful when evaluating community contributions.
It is always recommended to prioritize official SDKs for stability and direct support. However, community contributions can extend the reach and utility of the Open Disease API within niche applications or specific development ecosystems.