---
source: https://carbone.io/documentation/developer/api-sdks/rust.html
title: "Generate documents and reports with Rust SDK"
description: "Generate report with Rust"
generated_at: "2026-07-08"
---

# Rust SDK

Generate report with Rust

Rust SDK to generate reports through the [Carbone Cloud API](/documentation/quickstart/getting-started/generate-a-document.md) in a few lines of code.

The source code is available on Github: [https://github.com/carboneio/carbone-sdk-rust](https://github.com/carboneio/carbone-sdk-rust)

## Install

```rust
[dependencies]
carbone-sdk-rust = "1.0.0"
```

## Quickstart

Try the following code to render a report in 10 seconds. Just insert your API key, the template ID you want to render, and the JSON data-set as a string. Get your API key on your Carbone account: [https://account.carbone.io/](https://account.carbone.io/).

```rust
use std::env;

use carbone_sdk_rust::config::Config;
use carbone_sdk_rust::carbone::Carbone;
use carbone_sdk_rust::types::{ApiJsonToken, JsonData};
use carbone_sdk_rust::template::TemplateId;

use carbone_sdk_rust::errors::CarboneError;

use std::fs::File;
use std::io::Write

#[tokio::main]
async fn main() -> Result<(), CarboneError> {

    let token = "Token";

    let config: Config = Default::default();

    let api_token = ApiJsonToken::new(token.to_string())?;

    let json_data_value = String::from(r#"
        {
            "data" : {
                "firstname" : "John",
                "lastname" : "Wick"
            },
            "convertTo" : "odt"
        }
    "#);

    let json_data = JsonData::new(json_data_value)?;

    let template_id = TemplateId::new("YourTemplateId".to_string())?;

    let carbone = Carbone::new(&config, Some(&api_token))?;

    let report_content = match carbone.generate_report_with_template_id(template_id, json_data).await {
        Ok(v) => v,
        Err(e) => panic!("{}", e.to_string())
    };

    let mut output_file = File::create("report.pdf").expect("Failed to create file");

    if let Err(e) = output_file.write_all(&report_content) {
        eprintln!("Failed to write to file: {:?}", e);
    }

    Ok(())
}
```

## SDK Constructor

Example of a new SDK instance for Carbone Cloud: Get your API key on your Carbone account: [https://account.carbone.io/](https://account.carbone.io/).

```rust
// For Carbone Cloud, provide your API Access Token as first argument:
let token = "Token";
let config: Config = Default::default();
let api_token = ApiJsonToken::new(token.to_string())?;
let carbone = Carbone::new(&config, Some(&api_token))?;
```

Example of a new SDK instance for Carbone On-premise or Carbone On-AWS:

```rust
// Define the URL of your Carbone On-premise Server or AWS EC2 URL:
let config: Config = Config::new("ON_PREMISE_URL".to_string(), "api_time_out_in_sec_in_u64", ApiVersion::new("4".to_string()).expect("REASON")).expect("REASON");
let carbone = Carbone::new(&config, None)?;
```

## Generate and Download Document

Generate a document from a local template file:

```rust
pub async fn generate_report( &self, template_name: String, template_data: Vec<u8>, json_data: JsonData, payload: Option<&str>, salt: Option<&str>);
```

Arguments details:

-   template\_name: filename of the template.
-   template\_data: The content of the file in Vec.
-   json\_data: A stringified JSON containing the data to populate the template.

**Or**, Generate a document from a template ID:

```rust
pub async fn generate_report_with_template_id( &self, template_id: TemplateId, json_data: JsonData);
```

Argument details:

-   template\_id: Template ID (Manage your templates on [Carbone Studio](https://studio.carbone.io))
-   json\_data: A stringified JSON containing the data to populate the template.

## Add Template

```rust
pub async fn upload_template(&self,file_name: &str,file_content: Vec<u8>,salt: Option<&str>);
```

Add a template as file-content Vec and the function returns the template ID as String.

## Delete Template

```rust
pub async fn delete_template(&self, template_id: TemplateId);
```

Delete a template by providing a template ID as template\_id, and it returns whether the request succeeded as a Boolean.

## Related topics

- [Python SDK](/documentation/developer/api-sdks/python.md)
- [PHP SDK](/documentation/developer/api-sdks/php.md)
- [NodeJS SDK](/documentation/developer/api-sdks/nodejs.md)
- [Javascript SDK](/documentation/developer/api-sdks/javascript.md)
- [Java SDK](/documentation/developer/api-sdks/java.md)
- [Go SDK](/documentation/developer/api-sdks/go.md)
