This library enables you to manage Artifactory resources such as users, groups, permissions, repositories, artifacts and access tokens in your applications. Based on Python 3.8+ type hints.
Since Artifactory 6.6.0 there is version 2 of the REST API for permission management, in case you have that version or higher, you need to pass api_version=2 to the constructor when you instantiate the class.
Basic authentication
from pyartifactory import Artifactory
art = Artifactory(url="ARTIFACTORY_URL", auth=('USERNAME','PASSWORD_OR_API_KEY'), api_version=1)
Authentication with access token
from pyartifactory import Artifactory
art = Artifactory(url="ARTIFACTORY_URL", access_token="your-access-token")
Note:
If you set both access_token and auth, the access_token authentication will be chosen
If you do not set any authentication method, API calls will be done without authentication (anonymous)
SSL Cert Verification Options
Specify a local cert to use as client side certificate
from pyartifactory import Artifactory
art = Artifactory(url="ARTIFACTORY_URL", auth=('USERNAME','PASSWORD_OR_API_KEY'), cert="/path_to_file/server.pem", api_version=1)
Specify a local cert to use as custom CA certificate
from pyartifactory import Artifactory
art = Artifactory(url="ARTIFACTORY_URL", auth=('USERNAME','PASSWORD_OR_API_KEY'), verify="/path_to_file/ca.pem", cert="/path_to_file/server.pem", api_version=1)
verify and cert configure certificates for distinct purposes. verify determines SSL/TLS certificate validation for the server, while cert supplies a client certificate for mutual authentication, as required by the server. You can use either one or both parameters as needed.
Disable host cert verification
from pyartifactory import Artifactory
art = Artifactory(url="ARTIFACTORY_URL", auth=('USERNAME','PASSWORD_OR_API_KEY'), verify=False, api_version=1)
verify can be also set as a boolean to enable/disable SSL host verification.
Timeout option
Use timeout option to limit connect and read timeout in case the artifactory server is not responding in a timely manner.
from pyartifactory import Artifactory
art = Artifactory(url="ARTIFACTORY_URL", auth=('USERNAME','PASSWORD_OR_API_KEY'), api_version=1, timeout=60)
timeout is None by default.
Admin objects
User
First, you need to create a new Artifactory object.
from pyartifactory import Artifactory
art = Artifactory(url="ARTIFACTORY_URL", auth=('USERNAME','PASSWORD_OR_API_KEY'))
Get the list of users:
users = art.users.list()
Get a single user:
user = art.users.get("test_user")
Create a user:
from pyartifactory.models import NewUser
# Create User
user = NewUser(name="test_user", password="test_password", email="user@user.com")
new_user = art.users.create(user)
# Update user
user.email = "test@test.com"
updated_user = art.users.update(user)
Update a user:
from pyartifactory.models import User
user = art.users.get("test_user")
# Update user
user.email = "test@test.com"
updated_user = art.users.update(user)
Delete a user:
art.users.delete("test_user")
Unlock a user:
art.users.unlock("test_user")
Group
Get the list of groups:
groups = art.groups.list()
Get a single group:
group = art.groups.get("group_name")
Create/Update a group:
from pyartifactory.models import Group
# Create a Group
group = Group(name="test_group", description="test_group")
new_group = art.groups.create(group)
# Update a Group
group.description = "test_group_2"
updated_group = art.groups.update(group)
Delete a group:
art.groups.delete("test_group")
Security
A set of methods for performing operations on apiKeys, passwords ...
Deploy an artifact to the specified destination by checking if the artifact content already exists in Artifactory.
If Artifactory already contains a user-readable artifact with the same checksum the artifact content is copied over
to the new location and returns a response without requiring content transfer.
Otherwise, a 404 error is returned to indicate that content upload is expected in order to deploy the artifact.
Note: The performance might suffer when deploying artifacts with checksums enabled.
Download an artifact
artifact = art.artifacts.download("<ARTIFACT_PATH_IN_ARTIFACTORY>", "<LOCAL_DIRECTORY_PATH>")
# artifact = art.artifacts.download("my-artifactory-repository/my/new/artifact/file.txt", "Desktop/my/local/directory")
# The artifact location is returned by the download method
# If you have not set a <LOCAL_DIRECTORY_PATH>, the artifact will be downloaded in the current directory
artifact = art.artifacts.copy("<CURRENT_ARTIFACT_PATH_IN_ARTIFACTORY>","<NEW_ARTIFACT_PATH_IN_ARTIFACTORY>")
# If you want to run a dryRun test, you can do the following:
# artifact = art.artifacts.copy("my-repository/current/artifact/path/file.txt","my-repository/new/artifact/path/file.txt", dryrun=True)
# It will return properties of the newly copied artifact
Move artifact to a new location
artifact = art.artifacts.move("<CURRENT_ARTIFACT_PATH_IN_ARTIFACTORY>","<NEW_ARTIFACT_PATH_IN_ARTIFACTORY>")
# You can also run a dryRun test with the move operation
# It will return properties of the newly moved artifact
Note: optional BuildProperties can be used to query the correct build info of interest.
build_properties = BuildProperties(diff="<older_build>")
build_info: BuildInfo = art.builds.get_build_info("<build_name>", "<build_number>", properties=build_properties)
# build_info contains diff between <build_number> and <older_build>
# started is the earliest build time to return
build_properties = BuildProperties(started="<yyyy-MM-dd'T'HH:mm:ss.SSSZ>")
build_info: BuildInfo = art.builds.get_build_info("<build_name>", "<build_number>", properties=build_properties)
Create build
build_create_request = BuildCreateRequest(name="<build_name>", number="<build_number>", started="<Build start time in the format of yyyy-MM-dd'T'HH:mm:ss.SSSZ>")
create_build = art.builds.create_build(build_create_request)