oras package

Subpackages

Submodules

oras.auth module

exception oras.auth. AuthenticationException [source]

Bases: Exception

An exception to raise when Authentication errors are fatal

oras.auth. get_auth_backend ( name = 'token' , session = None , insecure = False , ** kwargs ) [source]

oras.client module

oras.container module

class oras.container. Container ( name : str , registry : str | None = None ) [source]

Bases: object

property api_prefix

Return the repository prefix for the v2 API endpoints.

get_blob_url ( digest : str ) str [source]

Get the URL to download a blob

Parameters :

digest ( str ) – the digest to download

manifest_url ( tag : str | None = None ) str [source]

Get the manifest url for a specific tag, or the one for this container.

The tag provided can also correspond to a digest.

Parameters :

tag ( None or str ) – an optional tag to provide (if not provided defaults to container)

parse ( name : str ) [source]

Parse the container name into registry, repository, and tag.

Parameters :

name ( str ) – the full name of the container to parse (with any components)

tags_url ( N = None ) str [source]
upload_blob_url ( ) str [source]
property uri : str

Assemble the complete unique resource identifier

oras.decorator module

oras.decorator. ensure_container ( func ) [source]

Ensure the first argument is a container, and not a string.

oras.decorator. retry ( attempts = 5 , timeout = 2 ) [source]

A simple retry decorator

oras.defaults module

class oras.defaults. registry [source]

Bases: object

default_v2_registry = {'host': 'registry-1.docker.io', 'scheme': 'https'}
index_hostname = 'index.docker.io'
index_name = 'docker.io'
index_server = 'https://index.docker.io/v1/'

oras.logger module

class oras.logger. ColorizingStreamHandler ( nocolor: bool = False , stream: str | ~pathlib.Path | ~typing.TextIO = <_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'> , use_threads: bool = False ) [source]

Bases: StreamHandler

BLACK = 0
BLUE = 4
BOLD_SEQ = '\x1b[1m'
COLOR_SEQ = '\x1b[%dm'
CYAN = 6
GREEN = 2
MAGENTA = 5
RED = 1
RESET_SEQ = '\x1b[0m'
WHITE = 7
YELLOW = 3
can_color_tty ( ) bool [source]

Determine if the tty supports color

colors = {'CRITICAL': 1, 'DEBUG': 4, 'ERROR': 1, 'INFO': 2, 'WARNING': 3}
decorate ( record ) str [source]

Decorate a log record

Parameters :

record – the record to emit

emit ( record : LogRecord ) [source]

Emit a log record

Parameters :

record ( logging.LogRecord ) – the record to emit

property is_tty : bool

Determine if we have a tty environment

class oras.logger. Logger [source]

Bases: object

cleanup ( ) [source]

Close open files, etc. for the logger

debug ( msg : str ) [source]

Debug level message

Parameters :

msg ( str ) – the debug message

error ( msg : str ) [source]

Error level message

Parameters :

msg ( str ) – the error message

exit ( msg : str , return_code : int = 1 ) [source]

Error level message and exit with error code

Parameters :
  • msg ( str ) – the exiting (error) message

  • return_code ( int ) – return code to exit on

handler ( msg : dict ) [source]

Handle a log message.

Parameters :

msg ( dict ) – the message to handle

info ( msg : str ) [source]

Info level message

Parameters :

msg ( str ) – the informational message

location ( msg : str ) [source]

Debug level message with location info.

Parameters :

msg ( dict ) – the logging message

progress ( done : int , total : int ) [source]

Show piece of a progress bar

Parameters :
  • done ( int ) – count of total that is complete

  • total ( int ) – count of total

set_level ( level : int ) [source]

Set the logging level.

Parameters :

level ( int ) – the logging level to set

set_stream_handler ( stream_handler : Handler ) [source]

Set a stream handler.

:param stream_handler : the stream handler :type stream_handler: logging.Handler

shellcmd ( msg : str | None ) [source]

Shellcmd message

Parameters :

msg ( str ) – the message

text_handler ( msg : dict ) [source]

The default log handler that prints to the console.

Parameters :

msg ( dict ) – the log message dict

warning ( msg : str ) [source]

Warning level message

Parameters :

msg ( str ) – the warning message

oras.logger. setup_logger ( quiet : bool = False , printshellcmds : bool = False , nocolor : bool = False , stdout : bool = False , debug : bool = False , use_threads : bool = False ) [source]

Setup the logger. This should be called from an init or client.

Parameters :
  • quiet ( bool ) – set logging level to quiet

  • printshellcmds ( bool ) – a special level to print shell commands

  • nocolor ( bool ) – do not use color

  • stdout ( bool ) – print to standard output for the logger

  • debug ( bool ) – debug level logging

  • use_threads ( bool ) – use threads!

oras.oci module

class oras.oci. Annotations ( filename = None ) [source]

Bases: object

Create a new set of annotations

add ( section , key , value ) [source]

Add key/value pairs to a named section.

get_annotations ( section : str ) dict [source]

Given the name (a relative path or named section) get annotations

load ( filename : str ) [source]
class oras.oci. Layer ( blob_path : str , media_type : str | None = None , is_dir : bool = False ) [source]

Bases: object

set_media_type ( media_type : str | None = None , is_dir : bool = False ) [source]

Vary the media type to be directory or default layer

Parameters :
  • media_type ( str ) – media type for the blob (optional)

  • is_dir ( bool ) – is the blob a directory?

to_dict ( ) [source]

Return a dictionary representation of the layer

oras.oci. ManifestConfig ( path : str | None = None , media_type : str | None = None ) Tuple [ Dict [ str , object ] , str | None ] [source]

Write an empty config, if one is not provided

Parameters :
  • path ( str ) – the path of the manifest config, if exists.

  • media_type ( str ) – media type for the manifest config (optional)

oras.oci. NewLayer ( blob_path : str , media_type : str | None = None , is_dir : bool = False ) dict [source]

Courtesy function to create and retrieve a layer as dict

Parameters :
  • blob_path ( str ) – the path of the blob for the layer

  • media_type ( str ) – media type for the blob (optional)

  • is_dir ( bool ) – is the blob a directory?

oras.oci. NewManifest ( ) dict [source]

Get an empty manifest config.

class oras.oci. Subject ( mediaType : str , digest : str , size : int ) [source]

Bases: object

digest : str
classmethod from_manifest ( manifest : dict ) Subject [source]

Create a new Subject from a Manifest

Parameters :

manifest – manifest to convert to subject

mediaType : str
size : int

oras.provider module

class oras.provider. Registry ( hostname : str | None = None , insecure : bool = False , tls_verify : bool = True , auth_backend : str = 'token' ) [source]

Bases: object

Direct interactions with an OCI registry.

This could also be called a “provider” when we add in the “copy” logic and the registry isn’t necessarily the “remote” endpoint.

chunked_upload ( blob : str , container : Container , layer : dict , chunk_size : int = 16777216 ) Response [source]

Upload via a chunked upload.

Parameters :
  • blob ( str ) – path to blob to upload

  • container ( oras.container.Container or str ) – parsed container URI

  • layer ( dict ) – dict from oras.oci.NewLayer

  • chunk_size ( int ) – chunk size in bytes

delete_tag ( container : str | Container , tag : str ) bool [source]

Delete a tag for a container.

Parameters :
delete_tags ( name : str , tags = typing.Union[str, list] ) List [ str ] [source]

Delete one or more tags for a unique resource identifier.

Returns those successfully deleted.

Parameters :
  • name ( str ) – container URI to parse

  • tags – single or multiple tags name to delete

do_request ( url : str , method : str = 'GET' , data : dict | bytes | None = None , headers : dict | None = None , json : dict | None = None , stream : bool = False ) [source]

Do a request. This is a wrapper around requests to handle retry auth.

Parameters :
  • url ( str ) – the URL to issue the request to

  • method ( str ) – the method to use (GET, DELETE, POST, PUT, PATCH)

  • data ( dict or bytes ) – data for requests

  • headers ( dict ) – headers for the request

  • json ( dict ) – json data for requests

  • stream ( bool ) – stream the responses

download_blob ( container : str | Container , digest : str , outfile : str ) str [source]

Stream download a blob into an output file.

This function is a wrapper around get_blob.

Parameters :

container ( oras.container.Container or str ) – parsed container URI

get_blob ( container : str | Container , digest : str , stream : bool = False , head : bool = False ) Response [source]

Retrieve a blob for a package.

Parameters :
  • container ( oras.container.Container or str ) – parsed container URI

  • digest ( str ) – sha256 digest of the blob to retrieve

  • stream ( bool ) – stream the response (or not)

  • head ( bool ) – use head to determine if blob exists

get_container ( name : str | Container ) Container [source]

Courtesy function to get a container from a URI.

Parameters :

name ( oras.container.Container or str ) – unique resource identifier to parse

get_manifest ( container : str | Container , allowed_media_type : list | None = None ) dict [source]

Retrieve a manifest for a package.

Parameters :
  • container ( oras.container.Container or str ) – parsed container URI

  • allowed_media_type ( str ) – one or more allowed media types

get_tags ( container : str | Container , N = None ) List [ str ] [source]

Retrieve tags for a package.

Parameters :
  • container ( oras.container.Container or str ) – parsed container URI

  • N ( Optional [ int ] ) – limit number of tags, None for all (default)

login ( username : str , password : str , password_stdin : bool = False , tls_verify : bool = True , hostname : str | None = None , config_path : str | None = None ) dict [source]

Login to a registry.

Parameters :
  • username ( str ) – the user account name

  • password ( str ) – the user account password

  • password_stdin ( bool ) – get the password from standard input

  • insecure ( bool ) – use http instead of https

  • tls_verify ( bool ) – verify tls

  • hostname ( str ) – the hostname to login to

  • config_path ( str ) – custom config path to add credentials to

logout ( hostname : str ) [source]

If auths are loaded, remove a hostname.

Parameters :

hostname ( str ) – the registry hostname to remove

pull ( target : str , config_path : str | None = None , allowed_media_type : List | None = None , overwrite : bool = True , outdir : str | None = None ) List [ str ] [source]

Pull an artifact from a target

Parameters :
  • config_path ( str ) – path to a config file

  • allowed_media_type ( list or None ) – list of allowed media types

  • overwrite ( bool ) – if output file exists, overwrite

  • manifest_config_ref ( str ) – save manifest config to this file

  • outdir ( str ) – output directory path

  • target ( str ) – target location to pull from

push ( target : str , config_path : str | None = None , disable_path_validation : bool = False , files : List | None = None , manifest_config : str | None = None , annotation_file : str | None = None , manifest_annotations : dict | None = None , subject : str | None = None , do_chunked : bool = False , chunk_size : int = 16777216 ) Response [source]

Push a set of files to a target

Parameters :
  • config_path ( str ) – path to a config file

  • disable_path_validation ( bool ) – ensure paths are relative to the running directory.

  • files ( list ) – list of files to push

  • insecure ( bool ) – allow registry to use http

  • annotation_file ( str ) – manifest annotations file

  • manifest_annotations ( dict ) – manifest annotations

  • target ( str ) – target location to push to

  • do_chunked ( bool ) – if true do chunked blob upload

  • chunk_size ( int ) – chunk size in bytes

  • subject ( oras.oci.Subject ) – optional subject reference

put_upload ( blob : str , container : Container , layer : dict ) Response [source]

Upload to a registry via put.

Parameters :
  • blob ( str ) – path to blob to upload

  • container ( oras.container.Container or str ) – parsed container URI

  • layer ( dict ) – dict from oras.oci.NewLayer

set_header ( name : str , value : str ) [source]

Courtesy function to set a header

Parameters :
  • name ( str ) – header name to set

  • value ( str ) – header value to set

upload_blob ( blob : str , container : str | Container , layer : dict , do_chunked : bool = False , chunk_size : int = 16777216 ) Response [source]

Prepare and upload a blob.

Large artifacts can be uploaded via a chunked approach (post, patch+, put) to registries that support it. Larger chunks generally give better throughput. Set do_chunked=True for chunked upload.

Parameters :
  • blob ( str ) – path to blob to upload

  • container ( oras.container.Container or str ) – parsed container URI

  • layer ( dict ) – dict from oras.oci.NewLayer

  • do_chunked ( bool ) – if true do chunked blob upload. This allows upload of larger oci artifacts.

  • chunk_size ( int ) – if true use chunked upload.

upload_manifest ( manifest : dict , container : Container ) Response [source]

Read a manifest file and upload it.

Parameters :
version ( return_items : bool = False ) dict | str [source]

Get the version of the client.

:param return_items : return the dict of version info instead of string :type return_items: bool

oras.provider. temporary_empty_config ( ) Generator [ str , None , None ] [source]

oras.schemas module

oras.version module

Module contents