Skip to main content

pycarta - Python Interface to Carta Platform

pycarta is a comprehensive Python library that streamlines administrative actions, service development, and integration with the Carta platform. It provides authentication controls, service hosting capabilities, MQTT messaging, data processing utilities, and seamless integration with external platforms like Seven Bridges Genomics.

Key Features

🔐 Authentication & Authorization

  • Unified authentication against Carta platform using AWS Cognito
  • Support for profiles, environment variables, and interactive login
  • Fine-grained authorization controls with the @pycarta.authorize decorator
  • Automatic authentication management across all modules
import pycarta

@pycarta.authorize(groups=["MyOrg:MyGroup"])
def my_function(*args, **kwds):
    # Code you want to protect.
    pass

🌐 Service Development

  • Create REST APIs using the @pycarta.service decorator
  • Automatic FastAPI integration with OpenAPI documentation
  • WebSocket support for real-time communication
  • Built-in authentication and authorization for service endpoints
import pycarta as pc

@pc.service("my-namespace", "my-service").get()
def hello_world():
    return {"message": "Hello from my service!"}

# Connect to Carta and serve your API
pc.service.connect()

📡 MQTT Messaging

  • Publisher and subscriber support with decorator-based APIs
  • Both synchronous and asynchronous MQTT clients
  • TLS/SSL support with credentials management
  • Quality of Service (QoS) support
from pycarta.mqtt import publish

@publish("my/topic")
def send_notification(message: str):
    return {"notification": message}

🗃️ Data Management

  • FormsDB: Schema-aware form data management with hierarchical organization
  • Tablify: JSON-to-DataFrame conversion with intelligent column ordering
  • Graph: NetworkX-based graph operations and algorithms

🧬 Seven Bridges Integration

  • Execute SBG Apps and Workflows as Python functions
  • Automatic file upload/download management
  • Multi-strategy authentication with fallback options
  • Progress tracking and cleanup management
from pycarta.sbg import ExecutableProject

pc.login()
project = ExecutableProject("division/my-project")
result = project.my_workflow(input_file="data.csv")

🛠️ Administrative Tools

  • User and group management
  • Service registration and namespace management
  • Permission and resource access control
  • Secret management for secure credential storage

Installation

pip install pycarta

For development or access to the latest features:

git clone https://gitlab.com/contextualize/pycarta
cd pycarta
pip install -e .

Quick Start

Authentication

import pycarta as pc

# Login using profiles (recommended)
pc.login(profile="my-profile")

# Or login interactively
pc.login(interactive=True)

# Or use environment variables
# CARTA_USER, CARTA_PASS, CARTA_PROFILE, CARTA_ENV
pc.login()

Creating a Service

import pycarta as pc

# Create a simple service
@pc.service("my-namespace", "calculator").get("/add/{a}/{b}")
def add_numbers(a: int, b: int):
    return {"result": a + b}

# Start the service
if __name__ == "__main__":
    pc.service.connect()

MQTT Messaging

from pycarta.mqtt import publish, subscribe

@publish("sensors/temperature")  
def temperature_reading():
    return {"temperature": 23.5, "timestamp": "2024-01-01T12:00:00Z"}

@subscribe("alerts/system")
def handle_alert(message):
    print(f"Alert received: {message}")

Data Processing

from pycarta.tablify import tablify
from pycarta.formsdb import Folder, Schema

# Convert JSON forms to DataFrame
df = tablify(json_data, schema=my_schema)

# Work with FormsDB
folder = Folder("my-project/data")
schema = Schema.create("user-form", json_schema)

Module Overview

Authentication (pycarta.auth)

  • CartaAgent: Main authentication agent with AWS Cognito integration
  • Profile: User profile management for storing credentials
  • Interactive Login: UI components with headless environment detection
  • Multi-factor Authentication: Support for various auth methods

Administrative Tools (pycarta.admin)

  • User Management: Create, search, and manage users
  • Group Management: Create groups and manage membership
  • Service Management: Register services and manage namespaces
  • Permission System: Fine-grained access control
  • Secret Management: Secure credential storage

Service Development (pycarta.services)

  • Service Decorator: @pycarta.service(namespace, service) for creating APIs
  • HTTP Methods: Support for GET, POST, PUT, PATCH, DELETE
  • WebSocket Proxy: Real-time communication capabilities
  • Auto-documentation: Automatic OpenAPI/ReDoc generation
  • Authentication: Built-in service-level authorization

MQTT Messaging (pycarta.mqtt)

  • Publisher: @publish(topic) decorator for message publishing
  • Subscriber: @subscribe(topic) decorator for message handling
  • Async Support: Both paho-mqtt and aiomqtt client support
  • TLS/SSL: Secure connections with credential management
  • QoS: Quality of Service support for reliable messaging

Data Management

FormsDB (pycarta.formsdb)

  • Hierarchical Organization: Folder-based data organization
  • Schema Management: JSON Schema support for validation
  • Data Versioning: Track changes and schema evolution
  • RESTful API: Integration with Carta FormsDB service

Tablify (pycarta.tablify)

  • JSON to DataFrame: Convert form data to pandas DataFrames
  • Schema-aware Processing: Intelligent column ordering
  • Nested Data Handling: Partial melting for complex structures
  • Command Line Interface: CLI support for batch processing

Graph Operations (pycarta.graph)

  • NetworkX Integration: Built on NetworkX DiGraph
  • Algorithms: Graph algorithms and utilities
  • Visitor Pattern: Extensible graph traversal

Seven Bridges Integration (pycarta.sbg)

  • ExecutableApp: Convert SBG Apps to Python functions
  • ExecutableProject: Convert entire projects to Python classes
  • File Management: Automatic upload/download handling
  • Authentication: Multi-strategy authentication with fallback
  • Progress Tracking: Built-in progress monitoring

Carta Platform Concepts

Core Entities

User: Someone with a registered Carta account

Group: Collection of users for permission management. Use namespaced naming (e.g., "MyOrg:MyGroup") to avoid conflicts

Project: Basic organizational unit in Carta, typically correlating to an organization

Service: API endpoints exposed through Carta with namespace/service scoping: https://carta.contextualize.us.com/<namespace>/<service>/{endpoints}

Resource: Shareable entities including projects, services, and secrets

Namespace: Unique identifier scope for services across the Carta platform

Permission System

Carta uses a comprehensive permission model:

  • Owner: Full control including permission management
  • Admin: Can grant/revoke permissions (except to owner)
  • Read: View access to resource
  • Write: Modify access to resource
  • Execute: Can call/run the resource (especially relevant for services)
  • Clone: Can duplicate the resource

Secrets Management

Secure storage for sensitive information like credentials and tokens:

  • User-specific (cannot be shared)
  • Encrypted at rest
  • Accessible across sessions
  • Useful for third-party service integration

Feature Request/Bug-Fix

For login issues, please contact customer.service@contextualize.us.com.

To request a new feature or to report a bug, please email pycarta. Please be sure to describe the goal of the new feature or, for a bug report, a minimum code that reproduces the error. Note that if you submit a feature request or bug report, the developers reserve the right to contact you about that request.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pycarta-0.3.12.tar.gz (229.2 kB view details)

Uploaded Source

Built Distribution

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

pycarta-0.3.12-py3-none-any.whl (173.7 kB view details)

Uploaded Python 3

File details

Details for the file pycarta-0.3.12.tar.gz.

File metadata

  • Download URL: pycarta-0.3.12.tar.gz
  • Upload date:
  • Size: 229.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.12.14

File hashes

Hashes for pycarta-0.3.12.tar.gz
Algorithm Hash digest
SHA256 889a961c718cb3afc800b99f991722abb8e581130c106c37aef0f5b3522656ad
MD5 81c2c99d0811e209661af68fa385af39
BLAKE2b-256 0f63cd46cfa81245b3c8bbe895259f1a510064c8adb657069ce3f0f108118822

See more details on using hashes here.

File details

Details for the file pycarta-0.3.12-py3-none-any.whl.

File metadata

  • Download URL: pycarta-0.3.12-py3-none-any.whl
  • Upload date:
  • Size: 173.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.12.14

File hashes

Hashes for pycarta-0.3.12-py3-none-any.whl
Algorithm Hash digest
SHA256 aa0506c7bfa530ecc1d1490cff515af2fe8b2903e7da45eb681f59b6312c872c
MD5 108edd415244c4c46cceb8cf6e797f32
BLAKE2b-256 3a3b4b03c7124bfc106977e16d420159b07c0fd79caff4ccfa32c5a4172c6027

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.3.12 This release

2 files

0.3.11

2 files

0.3.10

2 files

0.3.9

2 files

0.3.8

2 files

0.3.7

2 files

0.3.6

2 files

0.3.5

2 files

0.3.4

2 files

0.3.3

2 files

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

0.2.4

2 files

0.2.3

2 files

0.2.2

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page