pyartifactory
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
- breaking When managing permissions with Artifactory versions 6.6.0 or higher, you must explicitly pass `api_version=2` to the `Artifactory` constructor. Failing to do so will result in using the older API version (defaulting to 1) and potential errors or incorrect behavior for permission-related operations.
- gotcha If both `access_token` and `auth` (username/password tuple) are provided to the `Artifactory` constructor, the `access_token` authentication method will take precedence. Your `auth` credentials will be ignored.
- gotcha Recent versions (e.g., v2.11.1, v2.8.1) have made certain model fields (like `BuildArtifact.type` and `OriginalChecksums` attributes) optional. While this fixed validation errors, users relying on these fields always being present or non-null in older code might encounter `None` values where they previously expected data.
- breaking Version `2.6.0` introduced backward compatibility issues that were later fixed in `v2.7.1`. Users upgrading from `v2.6.0` to `v2.7.0` (or newer if `v2.7.1` wasn't applied) may encounter regressions or unexpected behavior due to changes that were not initially backward-compatible.
Install
-
pip install pyartifactory
Imports
- Artifactory
from pyartifactory import Artifactory
- NewUser
from pyartifactory.models import NewUser
Quickstart
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()