DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Monitoring and Logging in Cloud Architecture With Python
  • Stop Using Spring Profiles Per Environment
  • Private Remote Maven Repository With Artipie
  • How To Validate Names Using Java

Trending

  • Implementing API Design First in .NET for Efficient Development, Testing, and CI/CD
  • How To Introduce a New API Quickly Using Quarkus and ChatGPT
  • Software Delivery at Scale: Centralized Jenkins Pipeline for Optimal Efficiency
  • ITBench, Part 1: Next-Gen Benchmarking for IT Automation Evaluation
  1. DZone
  2. Data Engineering
  3. Databases
  4. Python SDKs Package Management in GCP Artifact Registry

Python SDKs Package Management in GCP Artifact Registry

This article provides tested and implemented best practices for managing Python SDKs in the GCP Artifact Registry, which allows for code reuse and security.

By 
Radhika Mekala user avatar
Radhika Mekala
·
Feb. 09, 22 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
4.3K Views

Join the DZone community and get the full member experience.

Join For Free

Introduction

Using a centralized, private repository to host SDK as a package not only enables code reuse but also simplifies and secures the existing software delivery pipeline. By using the same formats and tools as you would in the open-source ecosystem, you can leverage the same advantages, simplify building, and keep business logic and applications secure.

Storing SDK packages in Google Cloud Artifact Registry not only enables SDK code reuse but also simplifies and secures your existing build pipeline. In addition to bringing your internal packages to a managed repository, using Artifact Registry also allows you to take additional steps to improve the security of your software delivery pipeline. 

In this tutorial, we will learn how to:

  1. Set up an Artifact Registry for Python SDK repository
  2. Upload an SDK package
  3. Install the SDK package

1. Set Up an Artifact Registry for Python SDK Repository

As a part of setting up an Artifact Registry for Python SDK repository, let's first set up a virtual environment called "pythnsdk" and then install Twine and the Artifact Registry keyring backend in the virtual environment.

Python
python3 -m venv pythnsdk
source pythnsdk/bin/activate
python -m pip install -U pip
pip install twine keyrings.google-artifactregistry-auth
keyring --list-backends


Log in to Google Cloud CLI with service account credentials.

Python
gcloud auth activate-service-account [SERVICE_ACCOUNT] --key-file=/path/key.json --project=PROJECT_ID


Now, create a new Python package repository in the current project named "python-sdk-repo" in the location us-west1.

Python
gcloud artifacts repositories create python-sdk-repo \
--repository-format=python \
--location=us-west1 \
--description="Python package repository"


To set up authentication with the Artifact Registry keyring backend, run the following command to print the repository configuration to add to your Python project.

Python
gcloud artifacts print-settings python


Update the .pypirc file that specifies repositories for publishing Python packages. Verify $HOME/.pypirc and $VIRTUAL_ENV/pip.conf files and check whether repository settings are matching to the intended Artifact Registry repository and other GCP project details that were set up earlier.

Python
cat $HOME/.pypirc

[distutils]
index-servers =
python-sdk-repo

[python-sdk-repo]
repository: https://us-west11-python.pkg.dev/PROJECT_ID/python-sdk-repo/


Python
cat $VIRTUAL_ENV/pip.conf

[global]
extra-index-url = https://us-west1-python.pkg.dev/PROJECT_ID/python-sdk-repo/simple/


Python
mkdir python-sdk

cd python-sdk


Now download the whole Python SDK folder structure from the project Git repository (this folder structure contains a Python SDK that is already packaged in dist/ folder ) to the python-sdk folder

2. Upload an SDK package

Upload the packages to the Artifact Registry Python SDK repository from your dist directory.

Python
twine upload --repository-url https://us-west1-python.pkg.dev/PROJECT_ID/python-sdk-repo/ dist/*


Now view the package in the repository.

Python
gcloud artifacts packages list --repository=python-sdk-repo


To view versions of a package, run the following command:

Python
gcloud artifacts versions list --package=PACKAGE


Where PACKAGE is the package ID.

3. Install the SDK package.

Run the following command to install the Python SDK package uploaded to Artifact Registry in local.

Python
pip install --index-url https://us-west1-python.pkg.dev/PROJECT_ID/python-sdk-repo/simple/ projectsdk


Note: Use Cloud Identity and Access Management (IAM) for repository access control.

The above procedure has been successfully implemented and tested on the GCP client environment, verified in the below screenshot on what messages are seen after successful installation of a SDK package as reference.

verification messages

verification messages

Python (language) Artifact (UML) Software development kit Repository (version control)

Opinions expressed by DZone contributors are their own.

Related

  • Monitoring and Logging in Cloud Architecture With Python
  • Stop Using Spring Profiles Per Environment
  • Private Remote Maven Repository With Artipie
  • How To Validate Names Using Java

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!