Create an import job

Stay organized with collections Save and categorize content based on your preferences.

Create a new import job in Cloud KMS.

Explore further

For detailed documentation that includes this code sample, see the following:

Code sample


To learn how to install and use the client library for Cloud KMS, see Cloud KMS client libraries.

def create_import_job(project_id, location_id, key_ring_id, import_job_id):
    Create a new import job in Cloud KMS.

        project_id (string): Google Cloud project ID (e.g. 'my-project').
        location_id (string): Cloud KMS location (e.g. 'us-east1').
        key_ring_id (string): ID of the Cloud KMS key ring (e.g. 'my-key-ring').
        import_job_id (string): ID of the import job (e.g. 'my-import-job').

    # Import the client library.
    from import kms

    # Create the client.
    client = kms.KeyManagementServiceClient()

    # Retrieve the fully-qualified key_ring string.
    key_ring_name = client.key_ring_path(project_id, location_id, key_ring_id)

    # Set paramaters for the import job, allowed values for ImportMethod and ProtectionLevel found here:

    import_method = kms.ImportJob.ImportMethod.RSA_OAEP_3072_SHA1_AES_256
    protection_level = kms.ProtectionLevel.HSM
    import_job_params = {"import_method": import_method, "protection_level": protection_level}

    # Call the client to create a new import job.
    import_job = client.create_import_job({"parent": key_ring_name, "import_job_id": import_job_id, "import_job": import_job_params})

    print('Created import job: {}'.format(

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.