dohq-artifactory: A Python Client for Artifactory
dohq-artifactory is an active Python interface library for JFrog Artifactory, released as version 1.0.1. It functions as a logical descendant of Python's `pathlib`, aiming for a similar interface, and was forked from the `parallels/artifactory` project to provide continued support and development. It supports Python versions 3.8 through 3.13. The library enables interaction with Artifactory for tasks such as managing artifacts, searching repositories, and handling administrative functions. It generally follows an on-demand release cadence based on feature development and bug fixes.
Warnings
- gotcha The library is imported via `from artifactory import ...` despite the PyPI package name being `dohq-artifactory`. This can lead to confusion if users expect `from dohq_artifactory import ...` or if another `artifactory` package exists in the environment.
- deprecated JFrog Artifactory itself has deprecated API keys as an authentication method. As of Artifactory version 7.98 (Q4 2024), creation of new API keys is disabled, with a push towards reference tokens. While `dohq-artifactory` still supports passing an API key via the `auth` or `apikey` parameter, users of newer Artifactory server versions should consider migrating to username/password or access tokens to avoid future compatibility issues.
- gotcha This library is designed as a 'logical descendant of pathlib', meaning interactions often mimic filesystem operations. Users accustomed to traditional HTTP client libraries might find this paradigm different and should review the documentation for `pathlib`-like methods such as `exists()`, `is_dir()`, `iterdir()`, and path concatenation (`/`).
Install
-
pip install dohq-artifactory
Imports
- ArtifactoryPath
from artifactory import ArtifactoryPath
- ArtifactoryPath
from artifactory import ArtifactoryPath
Quickstart
import os
from artifactory import ArtifactoryPath
ART_URL = os.environ.get('ARTIFACTORY_URL', 'https://artifactory.example.com/artifactory')
ART_USER = os.environ.get('ARTIFACTORY_USERNAME', 'admin')
ART_PASS = os.environ.get('ARTIFACTORY_PASSWORD', 'password') # Or API Key/Access Token
try:
# Initialize ArtifactoryPath with URL and authentication
artifactory_path = ArtifactoryPath(ART_URL, auth=(ART_USER, ART_PASS))
# Example: List contents of a repository (e.g., 'libs-release')
repo = artifactory_path / "libs-release"
print(f"Contents of {repo}:")
for item in repo:
print(f" - {item.name} ({'dir' if item.is_dir() else 'file'})")
# Example: Access a specific artifact (assuming it exists)
artifact_path = repo / "com" / "example" / "myapp" / "1.0.0" / "myapp-1.0.0.jar"
if artifact_path.exists():
print(f"\nArtifact found: {artifact_path.name}")
print(f" Size: {artifact_path.stat().size} bytes")
else:
print(f"\nArtifact not found: {artifact_path}")
except Exception as e:
print(f"An error occurred: {e}")