SDKs overview

Postali offers a suite of Software Development Kits (SDKs) and client libraries designed to streamline interaction with its core APIs, including the Geocoding API, Reverse Geocoding API, and Address Validation API. These SDKs abstract the complexities of direct HTTP requests, authentication, and response parsing, allowing developers to integrate location data functionalities more efficiently into their applications. The official SDKs are available for a range of popular programming languages, ensuring broad compatibility for various development environments.

Using an SDK can reduce development time and potential errors by providing idiomatic language constructs for API calls. For instance, instead of manually constructing a URL, adding headers, and parsing JSON responses, a developer can call a simple function like postali.geocode('1600 Amphitheatre Parkway'). This approach aligns with common development practices for integrating external services, as exemplified by other API providers like Stripe's API documentation, which also emphasizes client library usage for ease of integration.

Postali's SDKs are designed to handle various aspects of API interaction, including:

  • Authentication: Securely managing API keys or tokens.
  • Request Formatting: Correctly structuring queries and parameters.
  • Response Parsing: Converting JSON API responses into native language objects.
  • Error Handling: Providing structured error responses for debugging.

For detailed API specifications and endpoints, developers can refer to the Postali API reference documentation.

Official SDKs by language

Postali maintains official SDKs for several programming languages, providing tested and supported methods for integration. These libraries are typically distributed through standard package managers for each language, simplifying installation and dependency management. The following table summarizes the key official SDKs:

Language Package/Module Name Install Command (Example) Maturity
JavaScript @postali/client npm install @postali/client or yarn add @postali/client Stable
Python postali-sdk pip install postali-sdk Stable
PHP postali/php-sdk composer require postali/php-sdk Stable
Ruby postali-ruby gem install postali-ruby Stable
Go github.com/postali/go-sdk go get github.com/postali/go-sdk Stable
Java com.postali:java-sdk Maven/Gradle dependency Stable
C# Postali.NET dotnet add package Postali.NET Stable

Each SDK is designed to reflect the native conventions of its respective language, offering an intuitive developer experience. For specific versioning and release notes, consult the Postali official documentation.

Installation

Installation of Postali SDKs typically involves using the standard package manager for the chosen programming language. Below are detailed installation instructions for the primary supported languages:

JavaScript (Node.js & Browser)

The JavaScript SDK can be installed using npm or yarn, making it suitable for both Node.js backend applications and frontend browser environments (via bundlers like Webpack or Rollup).

npm install @postali/client
# or
yarn add @postali/client

Python

The Python SDK is distributed via PyPI and can be installed using pip. It is recommended to install it within a virtual environment to manage dependencies effectively.

pip install postali-sdk

PHP

For PHP projects, the SDK is available through Composer, the dependency manager for PHP. Add the package to your composer.json file or run the command directly.

composer require postali/php-sdk

Ruby

The Ruby SDK is published as a gem. You can install it using the gem command or by adding it to your Gemfile and running bundle install.

gem install postali-ruby

Go

Go modules are used to manage the Go SDK. You can fetch the module using the go get command.

go get github.com/postali/go-sdk

Java

For Java projects, the Postali SDK can be included as a dependency in your Maven pom.xml or Gradle build.gradle file. Consult the Postali Java SDK documentation for the latest dependency coordinates.



    com.postali
    java-sdk
    1.0.0 

// Gradle example
implementation 'com.postali:java-sdk:1.0.0' // Use the latest version

C# (.NET)

The C# SDK is available as a NuGet package. You can install it using the .NET CLI or through the NuGet Package Manager in Visual Studio.

dotnet add package Postali.NET

Quickstart example

This section provides a basic quickstart example using the Postali Geocoding API to convert an address into geographical coordinates. The example demonstrates the typical pattern of initializing the client with an API key and making a simple API call.

Python Quickstart (Geocoding)

This Python example uses the postali-sdk to geocode a given address and print the resulting latitude and longitude. Ensure your API key is configured as an environment variable or replaced directly in the code for testing.

import os
from postali_sdk import PostaliClient

# Initialize the client with your Postali API key
# It's recommended to store your API key in an environment variable
api_key = os.environ.get("POSTALI_API_KEY")
if not api_key:
    print("Error: POSTALI_API_KEY environment variable not set.")
    exit()

client = PostaliClient(api_key=api_key)

# Address to geocode
address = "1600 Amphitheatre Parkway, Mountain View, CA"

try:
    # Call the geocode API
    response = client.geocode(address=address)

    if response and response.get("status") == "success":
        results = response.get("results", [])
        if results:
            first_result = results[0]
            latitude = first_result.get("latitude")
            longitude = first_result.get("longitude")
            formatted_address = first_result.get("formattedAddress")
            print(f"Address: {formatted_address}")
            print(f"Latitude: {latitude}, Longitude: {longitude}")
        else:
            print(f"No geocoding results found for '{address}'.")
    else:
        error_message = response.get("message", "Unknown error")
        print(f"Geocoding failed: {error_message}")

except Exception as e:
    print(f"An error occurred: {e}")

JavaScript Quickstart (Geocoding - Node.js)

This JavaScript example demonstrates how to use the @postali/client package in a Node.js environment to perform a geocoding lookup. It follows a similar structure to the Python example, emphasizing environment variable usage for API key security.

const { PostaliClient } = require('@postali/client');

// Initialize the client with your Postali API key
// It's recommended to store your API key in an environment variable
const apiKey = process.env.POSTALI_API_KEY;

if (!apiKey) {
    console.error('Error: POSTALI_API_KEY environment variable not set.');
    process.exit(1);
}

const client = new PostaliClient(apiKey);

// Address to geocode
const address = '1600 Amphitheatre Parkway, Mountain View, CA';

async function geocodeAddress() {
    try {
        // Call the geocode API
        const response = await client.geocode({ address: address });

        if (response && response.status === 'success') {
            const results = response.results;
            if (results && results.length > 0) {
                const firstResult = results[0];
                const { latitude, longitude, formattedAddress } = firstResult;
                console.log(`Address: ${formattedAddress}`);
                console.log(`Latitude: ${latitude}, Longitude: ${longitude}`);
            } else {
                console.log(`No geocoding results found for '${address}'.`);
            }
        } else {
            const errorMessage = response.message || 'Unknown error';
            console.error(`Geocoding failed: ${errorMessage}`);
        }
    } catch (error) {
        console.error(`An error occurred: ${error.message}`);
    }
}

geocodeAddress();

For more detailed examples and specific API endpoint usage, refer to the Postali code examples section within the official documentation.

Community libraries

While Postali provides official SDKs, the open-source community may also develop and maintain unofficial client libraries or integrations. These community-driven projects can sometimes offer alternative approaches, support for less common languages, or specialized functionalities not present in the official SDKs.

Community libraries are typically found on platforms like GitHub, GitLab, or language-specific package repositories (e.g., PyPI for Python, npm for JavaScript). When considering a community library, it is advisable to evaluate its:

  • Maintenance Status: How recently has it been updated? Is it actively maintained?
  • Documentation: Is there clear and comprehensive documentation?
  • Community Support: Are there active users or contributors?
  • Compatibility: Is it compatible with the latest Postali API versions?
  • Security: Has the code been reviewed for potential security vulnerabilities?

For instance, the broader ecosystem of API clients often includes tools that adhere to specifications like OpenAPI Specification (formerly Swagger), which allows for automatic client generation. While Postali's official SDKs are purpose-built, developers can sometimes use OpenAPI generators with Postali's API definition to create clients for unsupported languages, although these might require manual adjustments.

As of the latest information, Postali's official documentation primarily directs users to its maintained SDKs. Developers seeking community libraries should search relevant package repositories or GitHub for projects tagged with "Postali" or "geocoding" in conjunction with their desired programming language. Always verify the source and reliability of third-party libraries before incorporating them into production systems.

For the most up-to-date information on any community-contributed libraries, checking the Postali documentation or community forums is recommended.