Skip to content

Instantly share code, notes, and snippets.

@mvdbeek
Created June 14, 2024 13:49
Show Gist options
  • Save mvdbeek/5827afd57d5e96343a0c0d8d4140198c to your computer and use it in GitHub Desktop.
Save mvdbeek/5827afd57d5e96343a0c0d8d4140198c to your computer and use it in GitHub Desktop.
create api key example
# Run from galaxy root with PYTHONPATH=lib GALAXY_CONFIG_FILE=config/galaxy.yml python example.py
import os
from scripts.db_shell import config
from galaxy.celery import get_galaxy_app
from galaxy.managers.api_keys import ApiKeyManager
EMAIL = "abc@abc.com"
os.environ["GALAXY_CONFIG_FILE"] = os.environ.get("GALAXY_CONFIG_FILE", config["config_file"])
app = get_galaxy_app()
user = app.user_manager.by_email(EMAIL) or app.user_manager.create(email=EMAIL, username="abcd", password="abcdef")
key = ApiKeyManager(app).get_or_create_api_key(user)
print(key)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment