SDKs overview
Newton offers Software Development Kits (SDKs) and libraries designed to facilitate programmatic interaction with its interactive mathematical notebook environment and computational engine. These tools allow developers to integrate Newton's capabilities into external applications, automate routine tasks, and programmatically manage notebook content and computations. The primary interface for these SDKs is the Newton API, which exposes endpoints for executing mathematical operations, manipulating data, and managing user-created notebooks.
The availability of SDKs across multiple programming languages aims to support a broad developer base, from those building web applications with JavaScript to data scientists and engineers working with Python or .NET. These libraries abstract away the complexities of direct HTTP requests to the Newton API, providing higher-level functions and object models that align with the idiomatic patterns of each language. This approach enables developers to focus on application logic rather than low-level API communication. Beyond official offerings, a growing ecosystem of community-contributed libraries extends Newton's reach into specialized domains or alternative programming paradigms.
Developers using Newton's SDKs can perform various operations, including submitting mathematical expressions for evaluation, retrieving results, uploading and downloading notebook files, and managing user authentication. Security best practices, such as using API keys or OAuth 2.0 for authentication, are integral to the SDKs' design, ensuring secure access to user data and computational resources. For example, understanding how OAuth 2.0 authorization flows work is crucial for implementing secure integrations.
Official SDKs by language
Newton provides official SDKs for several popular programming languages, ensuring robust and supported integrations. These SDKs are maintained by the Newton team and are designed to offer the most current and stable access to the Newton platform's capabilities. Each SDK is tailored to the specific language's conventions, offering a natural development experience for users of that language.
| Language | Package Name | Install Command | Maturity |
|---|---|---|---|
| Python | newton-client |
pip install newton-client |
Stable |
| JavaScript | @newton/client |
npm install @newton/client or yarn add @newton/client |
Stable |
| .NET (C#) | Newton.Client |
dotnet add package Newton.Client |
Stable |
Each official SDK is typically published to its respective language's package manager, simplifying dependency management and updates. For instance, the Python SDK is available on PyPI, JavaScript on npm, and the .NET SDK on NuGet. Detailed documentation for each SDK, including API references and usage examples, is available on the Newton developer documentation portal.
The design philosophy behind these SDKs emphasizes ease of use and consistency. Common operations, such as authenticating with the API, making requests, and handling responses, are standardized across languages where possible, reducing the learning curve for developers working with multiple SDKs. Furthermore, the official SDKs are built to be forward-compatible with new API versions, with clear migration guides provided for any breaking changes, although such changes are minimized in stable releases. For example, the Python SDK adheres to common Pythonic practices, making it intuitive for experienced Python developers to integrate Newton functionality into their existing applications or scripts for scientific computing tasks.
Installation
Installing Newton's SDKs is straightforward, utilizing standard package managers for each language. This section provides specific instructions for each official SDK.
Python SDK
The Python SDK, newton-client, is distributed via PyPI. Ensure you have Python 3.7+ and pip installed. You can install it using the following command:
pip install newton-client
To upgrade to the latest version, use:
pip install --upgrade newton-client
It is generally recommended to install Python packages within a virtual environment to manage dependencies effectively and avoid conflicts with system-wide packages. After activating your virtual environment, run the installation command.
JavaScript SDK
The JavaScript SDK, @newton/client, is available on npm. You will need Node.js and npm (or yarn) installed. For Node.js projects or front-end applications, use:
npm install @newton/client
Alternatively, if you use Yarn:
yarn add @newton/client
For browser-based applications, the SDK can also be included via a CDN, though direct installation is recommended for modern development workflows. The JavaScript SDK is compatible with both CommonJS and ES module systems, allowing integration into various project types.
.NET (C#) SDK
The .NET SDK, Newton.Client, is distributed through NuGet. Ensure you have the .NET SDK installed. To add the package to your C# project, navigate to your project directory in the terminal and run:
dotnet add package Newton.Client
Alternatively, you can use the NuGet Package Manager in Visual Studio:
- Right-click on your project in Solution Explorer.
- Select "Manage NuGet Packages..."
- Search for
Newton.Clientand click "Install".
The .NET SDK supports .NET Standard 2.0 and above, ensuring compatibility with a wide range of .NET applications, including .NET Core, .NET 5+, and Xamarin projects. The SDK uses asynchronous programming patterns, aligning with modern .NET development practices for non-blocking I/O operations.
Quickstart example
This quickstart demonstrates how to use the Python SDK to authenticate with the Newton API, evaluate a simple mathematical expression, and retrieve the result. Before running, ensure you have your Newton API key available.
import os
from newton_client import NewtonClient
# Replace with your actual API Key or set as environment variable
api_key = os.environ.get("NEWTON_API_KEY", "YOUR_NEWTON_API_KEY")
if not api_key or api_key == "YOUR_NEWTON_API_KEY":
raise ValueError("Please set the NEWTON_API_KEY environment variable or replace 'YOUR_NEWTON_API_KEY' with your actual API key.")
# Initialize the Newton client
# The base_url can be customized if you are using a self-hosted or different Newton instance
client = NewtonClient(api_key=api_key, base_url="https://api.newton.so/v1")
# Define the mathematical expression to evaluate
expression = "integrate(x^2, x, 0, 1)"
try:
# Evaluate the expression
print(f"Evaluating expression: {expression}")
response = client.evaluate_expression(expression)
# Print the result
if response.success:
print(f"Result: {response.result}")
print(f"Calculated at: {response.timestamp}")
else:
print(f"Error evaluating expression: {response.error_message}")
except Exception as e:
print(f"An error occurred: {e}")
# Example of creating a new notebook (optional)
# try:
# new_notebook = client.create_notebook(name="My First SDK Notebook", content="# New Notebook Content")
# print(f"Created notebook with ID: {new_notebook.id}")
# except Exception as e:
# print(f"Error creating notebook: {e}")
This example first imports the necessary NewtonClient class and initializes it with an API key. It then calls the evaluate_expression method, passing a string representing a definite integral. The response object is checked for success, and the result or an error message is printed to the console. This basic structure can be extended to interact with other Newton API endpoints, such as managing notebooks, uploading data, or retrieving computation history, as detailed in the Newton Python SDK reference.
Community libraries
In addition to the official SDKs, the Newton ecosystem benefits from various community-contributed libraries. These libraries often extend Newton's functionality into niche areas, provide integrations with other tools, or offer alternative interfaces to the Newton API. While not officially supported by Newton, community libraries can provide valuable tools and insights, especially for specialized use cases.
Examples of community-driven efforts might include:
- Newton-R: An R package for interacting with the Newton API, enabling R users to leverage Newton's computational engine directly from their R scripts and environments for statistical computing.
- Newton-Excel-Addin: An Excel add-in that allows users to send mathematical expressions from Excel spreadsheets to Newton for evaluation and retrieve results back into Excel.
- Newton-CLI: A command-line interface tool built on top of one of the official SDKs, offering a scriptable way to interact with Newton without writing full programs.
Developers interested in exploring community libraries or contributing their own can typically find them on platforms like GitHub, PyPI (for Python), or npm (for JavaScript). It is advisable to review the documentation, source code, and community support channels for any third-party library before integrating it into production systems, as their maintenance and stability can vary. The Newton community forums and developer Discord channels are good places to discover new community projects and share experiences.
These community initiatives often demonstrate innovative ways to use the Newton API and can serve as inspiration for developing custom integrations. While the official SDKs prioritize stability and comprehensive API coverage, community libraries frequently experiment with new paradigms or target specific developer workflows not yet covered by official offerings. Developers are encouraged to check the Newton community page for pointers to active projects and discussion forums.