Skip to main content

A Python SDK for the Nexla API

Project description

Nexla Python SDK

A Python SDK for interacting with the Nexla API.

Installation

pip install nexla-sdk

Authentication

The Nexla SDK requires a Service Key for authentication. You can create a service key from the Nexla UI:

  1. Go to your Nexla UI instance (e.g., https://dataops.nexla.io)
  2. Navigate to the Authentication screen in the Settings section
  3. Click the Create Service Key button
  4. Store the service key securely - it should be treated as highly sensitive since it is equivalent to your account password

Quick Start

from nexla_sdk import NexlaClient

# Initialize the client with your service key
client = NexlaClient(service_key="your_nexla_service_key")

# List flows - returns a FlowList object with typed items
flows = client.flows.list()
print(f"Found {flows.total} flows")

# Access Flow objects with proper typing
for flow in flows.items:
    print(f"Flow name: {flow.name}, ID: {flow.id}")
    print(f"Active: {flow.config.is_active}")

# Get a specific flow - returns a Flow object
flow = client.flows.get("flow_id")
print(f"Flow details: {flow.name}, type: {flow.flow_type}")

# Create a data source
source_data = {
    "name": "My New Source",
    "description": "Created via SDK",
    "config": {
        "connector_type": "file",
        # Additional configuration...
    }
}

# Returns a Source object with proper typing
new_source = client.sources.create(source_data)
print(f"Created source: {new_source.id}, name: {new_source.name}")

Features

The SDK provides access to the following Nexla API features:

  • Flows management
  • Sources management
  • Destinations (Data Sinks) management
  • Nexsets (Data Sets) management
  • Credentials management
  • Data Maps (Lookups) management
  • Transforms management
  • Webhooks integration
  • Organization management
  • User management
  • Teams management
  • Projects management
  • Audit Logs
  • Metrics
  • Notifications
  • Schemas
  • Quarantine Settings

Type-Safe Models

The Nexla SDK uses Pydantic models to provide type safety and validation for API responses. All API methods return properly typed model objects instead of raw dictionaries:

# Get a flow - returns a Flow object
flow = client.flows.get("flow_id")

# Access properties with proper typing
print(flow.name)
print(flow.config.is_active)
print(flow.status.status if flow.status else "No status")

# List sources - returns a SourceList object
sources = client.sources.list()

# Access typed items
for source in sources.items:
    print(f"Source: {source.name}")
    print(f"Connector type: {source.config.connector_type}")

Examples

The Nexla SDK comes with a comprehensive set of examples in the examples/api/ directory:

Example Structure

  • examples/api/client.py - Base client configuration used by all examples
  • Resource-specific examples:
    • examples/api/flows.py - Flow operations (listing, retrieval, activation/pause)
    • examples/api/sources.py - Data source operations (listing, creation, updating, inspection)
    • examples/api/destinations.py - Data destination operations
    • examples/api/nexsets.py - Nexset (dataset) operations
    • examples/api/credentials.py - Credential management
    • examples/api/transforms.py - Data transformation operations
    • examples/api/lookups.py - Data Maps (Lookups) examples
    • examples/api/teams.py - Team management examples
    • examples/api/users.py - User management examples
    • And more resource-specific examples (audit_logs, metrics, notifications, etc.)

Running the Examples

To run these examples:

  1. Clone the repository
  2. Create a .env file with your Nexla credentials:
    NEXLA_SERVICE_KEY=your_service_key
    NEXLA_API_URL=your_api_url  # Optional, defaults to standard Nexla API URL
    
  3. Run any example script, for instance:
    python examples/api/flows.py
    

Example: Working with Flows

# List all flows - returns a FlowList
flows = client.flows.list()

# Get details of a specific flow - returns a Flow
flow = client.flows.get("flow_id")

# Activate a flow - returns the updated Flow
activated_flow = client.flows.activate("flow_id")
print(f"Flow activated: {activated_flow.config.is_active}")

# Pause a flow - returns the updated Flow
paused_flow = client.flows.pause("flow_id")
print(f"Flow active: {paused_flow.config.is_active}")

# Create a copy of a flow - returns the new Flow
new_flow = client.flows.copy("flow_id", new_name="Copy of my flow")
print(f"New flow created: {new_flow.id}, name: {new_flow.name}")

Example: Working with Data Sources

# List all data sources - returns a SourceList
sources = client.sources.list()

# Get details of a specific data source - returns a Source
source = client.sources.get("source_id")

# Create a new data source - returns a Source
source_config = {
    "name": "My API Source",
    "description": "Created via SDK",
    "config": {
        "connector_type": "rest_api",
        # Other configuration properties...
    }
}
new_source = client.sources.create(source_config)
print(f"New source ID: {new_source.id}")

# Activate a data source - returns the updated Source
activated_source = client.sources.activate("source_id")

Example: Working with Credentials

# List all credentials - returns a CredentialList
credentials = client.credentials.list()

# Create a new credential - returns a Credential
cred_config = {
    "name": "AWS S3 Credential",
    "credential_type": "aws_s3",
    "credential_details": {
        "credential_type": "aws_s3",
        "properties": {
            "access_key": "your_access_key",
            "secret_key": "your_secret_key",
            "region": "us-west-2"
        }
    }
}
new_credential = client.credentials.create(cred_config)
print(f"New credential ID: {new_credential.id}")

# Test a credential - returns a ProbeResult
probe_result = client.credentials.probe("credential_id")
print(f"Probe success: {probe_result.success}")

# Get a directory tree for a credential - returns a DirectoryTree
tree = client.credentials.probe_tree("credential_id", path="/some/path")
for item in tree.items:
    print(f"{item.name} ({item.type}): {item.path}")

Additional Example Features

The SDK examples cover advanced operations such as:

  • Audit logging and compliance tracking
  • User and team permissions management
  • Data transformation and schema handling
  • Metrics collection and monitoring
  • Notification systems integration
  • Quarantine settings for data validation

See the examples/api/ directory for detailed examples of these operations.

Error Handling

The SDK provides specific error classes for different error types:

from nexla_sdk import NexlaClient
from nexla_sdk.exceptions import NexlaAPIError, NexlaAuthError, NexlaValidationError

client = NexlaClient(service_key="your_nexla_service_key")

try:
    flows = client.flows.list()
except NexlaAuthError:
    print("Authentication failed. Please check your service key.")
except NexlaAPIError as e:
    print(f"API error: {str(e)}, Status code: {e.status_code}")
except NexlaValidationError as e:
    print(f"Validation error: {str(e)}")

License

This project is licensed under the terms of the MIT license.

Development

Running Integration Tests

The SDK includes a comprehensive suite of integration tests that verify the functionality against a real Nexla API instance. These tests create temporary test resources, perform operations on them, and then clean up.

To run the integration tests:

  1. Set up your environment variables:

    export NEXLA_TEST_API_URL="https://your-nexla-api-url"
    export NEXLA_TEST_SERVICE_KEY="your-nexla-service-key"
    export NEXLA_TEST_API_VERSION="v1"  # Optional, defaults to v1
    export NEXLA_TEST_LOG_LEVEL="INFO"  # Optional, defaults to INFO
    

    Alternatively, create a .env file in the project root or tests directory with these variables.

  2. Run the tests using the provided script:

    ./run_integration_tests.py
    

    Or use pytest directly:

    pytest -v -m integration tests/api/
    

The integration tests cover:

  • Flows API (create, get, update, delete, list, activate/pause, tags)
  • Sources API (create, get, update, delete, list, activate/pause)
  • Nexsets API (Data Sets) (create, get, update, delete, list, schema, samples)
  • Projects API (create, get, update, delete, list, add/remove flows)
  • Users API (get current user, preferences, list users, metrics)

Note: These tests require API credentials with appropriate permissions to create and manage resources.

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

nexla_sdk-0.1.8.tar.gz (129.2 kB view details)

Uploaded Source

Built Distribution

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

nexla_sdk-0.1.8-py3-none-any.whl (88.0 kB view details)

Uploaded Python 3

File details

Details for the file nexla_sdk-0.1.8.tar.gz.

File metadata

  • Download URL: nexla_sdk-0.1.8.tar.gz
  • Upload date:
  • Size: 129.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for nexla_sdk-0.1.8.tar.gz
Algorithm Hash digest
SHA256 eb714a51c10b156308ebbc6ad8c45dbf67b43109bd63a6a971a8b3936808a3d1
MD5 b50326caad9145608e3df4d75e288548
BLAKE2b-256 e3fcb3f90f86791b5fb3357b16cfd4938d5d6ea6d7619f02ed92b711d47cb606

See more details on using hashes here.

Provenance

The following attestation bundles were made for nexla_sdk-0.1.8.tar.gz:

Publisher: release.yml on nexla-opensource/nexla-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nexla_sdk-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: nexla_sdk-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 88.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for nexla_sdk-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 af8a496c5f0eef009f27c7410d056d30ce7919ee3717e2850f4be86aad6c81d7
MD5 d69d1e8cf097257c11ac84dc14dae1ae
BLAKE2b-256 2fd88613263609456396a6ed14dd5e88ac96bec1307f46d3651586fb9faffd61

See more details on using hashes here.

Provenance

The following attestation bundles were made for nexla_sdk-0.1.8-py3-none-any.whl:

Publisher: release.yml on nexla-opensource/nexla-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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