# Recipe for Success: Creating, Updating, and Deleting Resources with the Transifex Python SDK

**URL:** https://community.transifex.com/t/recipe-for-success-creating-updating-and-deleting-resources-with-the-transifex-python-sdk/4279
**Category:** Tips and Tricks
**Tags:** api, python-api-sdk, code-chef
**Created:** [November 6, 2024, 2:54pm UTC](https://community.transifex.com/t/recipe-for-success-creating-updating-and-deleting-resources-with-the-transifex-python-sdk/4279 "2024-11-06T14:54:10Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Panagiotis\_Kavrakis](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.transifex.com/panagiotis_kavrakis/32/1402_2.png) [@Panagiotis\_Kavrakis](https://community.transifex.com/u/Panagiotis_Kavrakis)
#### Post date: [November 6, 2024, 2:54pm UTC](https://community.transifex.com/t/recipe-for-success-creating-updating-and-deleting-resources-with-the-transifex-python-sdk/4279/1 "2024-11-06T14:54:10Z")

</div>

Hello, fellow code enthusiasts! 👩‍🍳👨‍🍳 Welcome back to ‘Script Chef,’ where we whip up coding recipes that bring your projects to life. Today, we’re stirring up a treat straight from the Transifex kitchen to help you master the art of resource management with the Transifex Python SDK.

In this guide, we’ll walk through a recipe for working with Transifex resources using the [Transifex Python SDK](https://pypi.org/project/transifex-python). You’ll learn how to create a new resource, upload content, and delete it when necessary. This step-by-step process will help you master the basics of resource management, all from the comfort of your Python environment!

### Ingredients You’ll Need

1. **The Transifex Python SDK** : Install the SDK directly from PyPI by running:

```auto
pip install transifex-python

```

1. **API Token** : Ensure you have a valid Transifex API token. This token allows the SDK to interact with your Transifex account.
2. **Organization and Project Slugs** : Identify the organization and project slugs where your resources will live.

### Step 1: Authenticate with Transifex API

To get started, import the SDK and set up authentication using your API token:

```auto
from transifex.api import transifex_api

# Replace with your actual API token
transifex_api.setup(auth="<YOUR-API-TOKEN>")

```

### Step 2: Retrieve Organization and Project

Once authenticated, you can access your organization and project information. Use the appropriate slugs to locate the project you want to work with:

```auto
organization = transifex_api.Organization.get(slug="<YOUR-ORG-SLUG>")
project = organization.fetch('projects').get(slug="<YOUR-PROJECT-SLUG>")

```

### Step 3: Create a New Resource

Define your resource format by specifying the i18n format you’ll use. In this example, we’ll use “KEYVALUEJSON,” commonly used for JSON files in localization.

```auto
# Specify the format
i18n_format = transifex_api.i18n_formats.get(
    organization=organization,
    name="KEYVALUEJSON")

# Create the resource
resource = transifex_api.Resource.create(
    name="<NEW-RESOURCE-NAME>",
    slug="<NEW-RESOURCE-SLUG>",
    i18n_format=i18n_format,
    project=project,
)

```

> **Tip** : Replace `<NEW-RESOURCE-NAME>` and `<NEW-RESOURCE-SLUG>` with unique identifiers for your resource. Resource names and slugs must be unique within a project.

### Step 4: Upload Content

To upload content to your newly created resource, define the content and use the `ResourceStringsAsyncUpload` method:

```auto
content = '{ "key": "value" }'
transifex_api.ResourceStringsAsyncUpload.upload(
  resource=resource, content=content
)

```

This command uploads the JSON-formatted string directly into the resource. Transifex handles the heavy lifting, parsing and adding the content to your project.

### Step 5: Delete the Resource

When it’s time to clean up, deleting a resource is just as simple as creating it. Call the `delete` method on the resource:

```auto
resource.delete()

```

## That’s It! You’re Done

With these simple steps, you’ve successfully created, updated, and deleted a resource in Transifex using Python. Feel free to experiment with different content formats and explore further capabilities of the Transifex SDK.

* * *

We hope you enjoyed this recipe from ‘Script Chef’! If you have any questions or need further assistance, don’t hesitate to contact our community or support team. Happy coding!
