pyartifactory

2.11.2 · active · verified Tue Apr 14

pyartifactory is a Python library providing typed interactions with the JFrog Artifactory REST API, currently at version 2.11.2. It enables developers to manage Artifactory resources such as users, groups, permissions, repositories, artifacts, and access tokens in their applications. The library maintains an active release cadence with frequent updates to add features and address issues.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `Artifactory` client using environment variables for credentials and then perform basic operations like listing users and creating a new user. It highlights the use of basic authentication and the `api_version` parameter for Artifactory 6.6.0+ permission management.

import os
from pyartifactory import Artifactory
from pyartifactory.models import NewUser

ART_URL = os.environ.get('ARTIFACTORY_URL', 'http://localhost:8081/artifactory')
ART_USER = os.environ.get('ARTIFACTORY_USERNAME', 'admin')
ART_PASS = os.environ.get('ARTIFACTORY_PASSWORD', 'password')

def main():
    try:
        # Initialize the Artifactory client using basic authentication
        # For Artifactory 6.6.0+ and permission management, consider api_version=2
        art = Artifactory(url=ART_URL, auth=(ART_USER, ART_PASS), api_version=1)
        print(f"Successfully connected to Artifactory at {ART_URL}.")

        # Example: List users
        users = art.users.list()
        print(f"Found {len(users)} users:")
        for user in users:
            print(f"- {user.name}")

        # Example: Create a new user (adjust name/email as needed)
        new_user_data = NewUser(
            name="test_user_ai",
            password="secure_password",
            email="test_user_ai@example.com"
        )
        try:
            created_user = art.users.create(new_user_data)
            print(f"User '{created_user.name}' created successfully.")
        except Exception as e:
            print(f"Could not create user 'test_user_ai' (might already exist): {e}")
        
    except Exception as e:
        print(f"An error occurred: {e}")

if __name__ == "__main__":
    main()

view raw JSON →