Skip to main content

Typed interactions with the Jfrog Artifactory REST API

Project description

PyArtifactory

GitHub Actions workflow PyPI version Codacy Badge Codacy Badge Code style: black

pyartifactory is a Python library to access the Artifactory REST API.

This library enables you to manage Artifactory resources such as users, groups, permissions, repositories, artifacts and access tokens in your applications. It requires at least Python 3.6

Install

pip install pyartifactory 

Usage

Authentication

from pyartifactory import Artifactory
art = Artifactory(url="ARTIFACTORY_URL", auth=('USERNAME','PASSWORD_OR_API_KEY'))

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','PASSORD_OR_API_KEY'), cert="/path_to_file/server.pem")

Disable host cert verification

from pyartifactory import Artifactory
art = Artifactory(url="ARTIFACTORY_URL", auth=('USERNAME','PASSORD_OR_API_KEY'), verify=False)

Admin objects

User

First, you need to create a new Artifactory object.

from pyartifactory import Artifactory
art = Artifactory(url="ARTIFACTORY_URL", auth=('USERNAME','PASSORD_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:

users = art.groups.list()

Get a single group:

users = 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 user
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 ...

>>> art.security.
art.security.create_api_key(          art.security.get_encrypted_password(  art.security.revoke_api_key(
art.security.get_api_key(             art.security.regenerate_api_key(      art.security.revoke_user_api_key(

Create an access token (for a transient user):

token = art.security.create_access_token(user_name='transient_artifactory_user', 
                                         groups=['g1', 'g2'],
                                         refreshable=True)

Create an access token for an existing user (groups are implied from the existing user):

token = art.security.create_access_token(user_name='existing_artifactory_user', 
                                         refreshable=True)

Revoke an existing revocable token:

art.security.revoke_access_token(token.access_token)

Repository

Get the list of repositories:

repositories = art.repositories.list()

Get a single repository (Local, Virtual or Remote):

local_repo = art.repositories.get_local_repo("local_repo_name")
virtual_repo = art.repositories.get_virtual_repo("virtual_repo_name")
remote_repo = art.repositories.get_remote_repo("remote_repo_name")

Create/Update a repository:

from pyartifactory.models import LocalRepository, VirtualRepository, RemoteRepository

# Create a repository
local_repo = LocalRepository(key="test_local_repo")
new_local_repo = art.repositories.create_local_repo(local_repo)

# Update a repository
local_repo.description = "test_local_repo"
updated_local_repo = art.repositories.update_local_repo(local_repo)

# Same process for Virtual and Remote repositories

Delete a repository:

art.repositories.delete("test_local_repo")

Permission

Get the list of permissions:

permissions = art.permissions.list()

Get a single permission:

users = art.permissions.get("test_permission")

Create/Update a permission:

from pyartifactory.models import Permission

# Create a permission
permission = Permission(
    **{
        "name": "test_permission",
        "repositories": ["test_repository"],
        "principals": {
            "users": {"test_user": ["r", "w", "n", "d"]},
            "groups": {"developers": ["r"]},
        },
    }
)
perm = art.permissions.create(permission)

# Update permission
permission.repositories = ["test_repository_2"]
updated_permission = art.permissions.update(permission)

Delete a permission:

art.permissions.delete("test_permission")

Artifacts

Deploy an artifact

artifact = art.artifacts.deploy("<LOCAL_FILE_LOCATION>", "<ARTIFACT_PATH_IN_ARTIFACTORY>")
# artifact = art.artifacts.deploy("Desktop/myNewFile.txt", "my-repository/my/new/artifact/directory/file.txt")

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

Retrieve artifact properties

artifact_properties = art.artifacts.properties("<ARTIFACT_PATH_IN_ARTIFACTORY>")
# artifact_properties = art.artifacts.properties("my-repository/my/new/artifact/directory/file.txt")
>>> print(artifact_properties.json)

Retrieve artifact stats

artifact_stats = art.artifacts.stats("<ARTIFACT_PATH_IN_ARTIFACTORY>")
# artifact_stats = art.artifacts.stats("my-repository/my/new/artifact/directory/file.txt")
>>> print(artifact_stats.json)

Copy artifact to a new location

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

Delete an artifact

art.artifacts.delete("<ARTIFACT_PATH_IN_ARTIFACTORY>")

Contributing

Please read the Development - Contributing guidelines.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PyArtifactory-1.3.1.tar.gz (15.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

PyArtifactory-1.3.1-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file PyArtifactory-1.3.1.tar.gz.

File metadata

  • Download URL: PyArtifactory-1.3.1.tar.gz
  • Upload date:
  • Size: 15.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.2 CPython/3.6.10 Linux/5.0.0-1032-azure

File hashes

Hashes for PyArtifactory-1.3.1.tar.gz
Algorithm Hash digest
SHA256 d32b6d8780f13044acc571d5a6d4b7efc3fc316c2bdfeeeb583d42bbaee0891e
MD5 bae8244d9ed9f3b3899fbdfbaa0d2095
BLAKE2b-256 b7c7a63c6b62933a08cda302d19504c744b4926ad8dc8cf078e588e88b4be23d

See more details on using hashes here.

File details

Details for the file PyArtifactory-1.3.1-py3-none-any.whl.

File metadata

  • Download URL: PyArtifactory-1.3.1-py3-none-any.whl
  • Upload date:
  • Size: 15.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.2 CPython/3.6.10 Linux/5.0.0-1032-azure

File hashes

Hashes for PyArtifactory-1.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9a8870f6f6edf68d0b94b932b1844aaf12c468370d2665a148e1c230fc18f8f7
MD5 69a93777b232426477aa219dcdca54f2
BLAKE2b-256 09af5e1293e3cba1c07d10e14fb6d006897ce5c0e8b8f955c13f003e1c9a268c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page