Create a New Project
This sample code shows how to use the API to create a new project under your project and add the recipes to the project.
import requests
from typing import List
def create_project(
api_key: str, owner: str, name: str, is_public: bool = False,
description: str = None, recipes: List[dict] = None
):
headers = {'x-pollination-token': api_key}
# create the project
url = f'https://api.pollination.solutions/projects/{owner}'
data = {
'name': name,
'description': description if description else '',
'public': is_public
}
print(f'Creating project {owner}/{name} ...')
response = requests.post(url=url, headers=headers, json=data)
response.raise_for_status()
print(f'Project {owner}/{name} is created!')
# add the recipes if any
recipes = recipes or []
recipe_url = f'https://api.pollination.solutions/projects/{owner}/{name}/recipes/filters'
for recipe in recipes:
# each recipe should be formatted as
# {'owner': 'owner', 'name':'name, 'tag': 'tag'}
print(f'Adding recipe {recipe} to the project.')
recipe_response = requests.post(
url=recipe_url, headers=headers, json=recipe
)
recipe_response.raise_for_status()
Here is an example of using the function to create a project under the Pollination organization.
Here are the screenshots of the project created using the sample code.


Last updated
Was this helpful?
