Oracle Cloud Infrastructure Python SDK

repository·master·Indexed 19 days ago

https://github.com/oracle/oci-python-sdk

A client library for interacting with Oracle Cloud Infrastructure (OCI) services. The SDK provides service clients and model classes for various OCI services, including Application Dependency Management (oci.adm) for managing software supply chain vulnerabilities and Access Governance Control Plane (oci.access_governance_cp) for managing governance instances and configurations.

Tokens
797.7K
Snippets
3.6K
Records
4.3K
Agent score
66%

What's inside oci-python-sdk

  1. Use Database Management clients in the OCI Python SDK

    master

    The oci.database_management module provides several specialized clients for managing Oracle Cloud Infrastructure database services. You can use these clients to interact with different aspects of database management, such as diagnostics, MySQL database management, performance hubs, and SQL tuning.

    Available clients include:

    • DbManagementClient: Core database management operations.
    • DiagnosabilityClient: Operations related to database diagnosability.
    • ManagedMySqlDatabasesClient: Management of managed MySQL databases.
    • PerfhubClient: Access to Performance Hub features.
    • SqlTuningClient: Operations for SQL tuning.

    Each client also provides a corresponding CompositeOperations class (e.g., DbManagementClientCompositeOperations) to handle complex, multi-step operations that require orchestration.

    import oci
    
    # Example of initializing a client
    # Note: Configuration typically requires an oci.config.ConfigFileReader
    config = oci.config.from_file()
    client = oci.database_management.DbManagementClient(config)
  2. Explore OCI Service Clients

    master
    The OCI Python SDK provides specialized service clients to interact with various Oracle Cloud Infrastructure services. Each client corresponds to a specific OCI service (e.g., ComputeClient for Compute, ObjectStorageClient for Object Storage, IdentityClient for Identity). You can use these clients to perform CRUD operations, manage resources, and query service states via their respective APIs.
  3. Customize OCI Service Clients

    master

    You can customize OCI SDK service clients to control request behavior and network settings. The available customization methods include:

    • Setting connection and read timeouts: Control how long the client waits to establish a connection or receive data.
    • Using a proxy server: Configure the SDK to route requests through a proxy.
    • Injecting custom headers: Add specific HTTP headers to every request sent by the client.
  4. Use the OCI Streaming service clients

    master

    The OCI Streaming service is managed through two primary client classes in the oci.streaming module:

    • StreamClient: Used for data plane operations, such as consuming messages and putting messages into streams.
    • StreamAdminClient: Used for control plane operations, such as creating, updating, or deleting streams and stream pools.

    Both clients provide CompositeOperations (e.g., StreamClientCompositeOperations) which allow for performing operations that include both a request and a subsequent wait for a work request to complete.

  5. Understand Osub usage data models

    master

    The Osub service uses several model classes to represent usage data and product information. When consuming API responses, you will interact with the following models:

    • oci.osub_usage.models.ComputedUsage: Represents specific computed usage data.
    • oci.osub_usage.models.ComputedUsageAggregatedSummary: Provides a summary of usage that has been aggregated.
    • oci.osub_usage.models.ComputedUsageAggregation: Defines the parameters or structure of a usage aggregation.
    • oci.osub_usage.models.ComputedUsageSummary: A high-level summary of computed usage.
    • oci.osub_usage.models.Product: Represents information about an OCI product related to usage.
  6. How deferred imports work in OCI Python SDK

    master

    Starting with version v2.88.1 for Python 3.7+, the SDK enables deferred imports by default. This feature automatically reduces initial load times by only importing the modules explicitly requested in your code.

    Compatibility Note:

    • If you are using Python 3.6 or a version older than v2.88.1, you must manually enable selective imports using the OCI_PYTHON_SDK_NO_SERVICE_IMPORTS=True environment variable.

    Opting Out: If deferred/lazy imports cause issues with your specific implementation, you can disable this feature by setting the following environment variable: OCI_PYTHON_SDK_LAZY_IMPORTS_DISABLED=True.

  7. Understand WorkRequestErrorCollection in Network Load Balancer

    master
    The WorkRequestErrorCollection class is a model used within the oci.network_load_balancer.models module. It represents a collection of errors associated with a Work Request in the Oracle Cloud Infrastructure (OCI) Network Load Balancer service. When performing asynchronous operations (Work Requests), this object is used to aggregate and return error details if the requested operation fails.
  8. How circuit breakers work in the OCI Python SDK

    master

    Circuit breakers prevent overwhelming services during outages by wrapping REST calls in a monitoring object. When failures reach a specific threshold, the circuit 'trips', and subsequent calls return an error immediately without attempting the network request. This protects the service from being flooded with retries during an outage.

    The circuit breaker operates in three states:

    1. Closed: The initial state. Requests pass through to the service. Successes reset the failure count; failures increment it. If the failure count hits the threshold, the state moves to Open.
    2. Open: No network calls are allowed for a specified recovery_timeout duration. After the timeout, the state moves to Half Open.
    3. Half Open: The circuit allows a single trial call to see if the service has recovered. If the call succeeds, it moves back to Closed. If it fails, the recovery_timeout restarts and the state returns to Open.
  9. Use OCI Usage Service models

    master

    The oci.usage.models module contains data structures used for requests and responses within the Usage service. These models represent entities such as:

    • Resource Data: ResourceSummary, ResourcesCollection, ResourceQuotumSummary, ResourceQuotumCollection.
    • Rewards & Redemptions: RewardDetails, RewardCollection, RedeemableUser, RedeemableUserSummary, RedemptionSummary, RedemptionCollection.
    • Usage Limits: UsageLimitSummary, UsageLimitCollection.
    • Product Information: ProductSummary, ProductCollection, SkuProducts.
  10. Handle unknown enum values in SDK responses

    master

    The OCI Python SDK uses enums for certain response fields. To maintain forward compatibility, if a service returns a value that is not recognized by your current version of the SDK, the field will be populated with the value UNKNOWN_ENUM_VALUE.

    If your application logic relies on conditional checks against specific enum values (e.g., if response.status == 'ACTIVE':), you must also account for the UNKNOWN_ENUM_VALUE case to prevent unexpected behavior when services introduce new states.

  11. Use Composite Operations to perform actions and wait for states

    master
    The SDK provides CompositeOperation classes (e.g., oci.core.ComputeClientCompositeOperations) to simplify workflows where you need to perform an action on a resource and immediately wait for it to reach a specific lifecycle state. These classes provide convenience methods that combine the initial service call and the subsequent waiting logic into a single step, preventing the need to manually invoke a waiter after every operation.
  12. How sensitive data redaction works in logs

    master

    When request logging or debug output is enabled, the SDK automatically redacts common credential-bearing values to prevent sensitive information from appearing in logs.

    Redaction Details:

    • Headers: Sensitive HTTP header values are replaced with REDACTED. Matching is case-insensitive and treats _ and - as equivalent.
    • Matched Headers include: authorization, proxy-authorization, opc-obo-token, x-api-key, cookie, set-cookie, security-context, password, passphrase.
    • Auth/Key Families: x-token*, x-authorization*, x-key-*.
    • Credential Suffixes: access-token, refresh-token, id-token, security-token, session-token, delegation-token, client-secret, private-key.
    • Query Strings: Token-like values found in query-string style data are also redacted.

    Note: Redaction applies to SDK-emitted logging paths. It does not cover application-specific logging, custom middleware, or manual printing of payloads.