Skip to main content

Architect Python SDK

This is the Python SDK used for brokering connections to microservice dependencies via Architect's deployment platform. If you're unfamiliar with the platform or our deploy tools, please check out Architect.io and our CLI to get started.

SDK Documentation

Connecting to dependencies

import architect.sdk as architect

my_dependency = architect.service('my_dependency_name')

# Client used to connect to service
client = my_dependency.client

# Dynamically imported models used for message formatting
# Used by protocols supporting code-gen like gRPC
defs = my_dependency.defs

REST

The Architect SDK uses the popular REST client, Requests, to broker communication to downstream REST microservices. The client that is provided is a requests session that is enriched with the proper service location meaning only URIs and HTTP actions need be provided:

res = my_dependency.client.get('/resource')
res = my_dependency.client.post('/resource', { data })
res = my_dependency.client.put('/resource/:resource_id', { data })
res = my_dependency.client.delete('/resource/:resource_id')

gRPC

Architect handles the code-gen for gRPC services for you. Every time you run $ architect install ..., you'll find relevant gRPC stubs generated and placed inside an architect_services folder in your service's root directory. This SDK handles the import of generated model objects for parsing input/output messages as well as the import and enrichment of client code for making calls to dependencies.

// service.proto
syntax = "proto3";

package example_service;

message PayRequest {
    int32 amount = 1;
}

message PayResponse {
    int32 output = 1;
}

service Example {
  rpc Pay (PayRequest) returns (PayResponse) {}
}
# Model definitions will match message names in the .proto file for the service
pay_req = my_dependency.defs.PayRequest(amount=10)

# Client will automatically have methods matching the service definition from 
# the dependency's .proto file. Response handling matches gRPC documentation.
pay_res = my_dependency.client.Pay(pay_req)
output = pay_res.output

Connecting to data stores

Since there are so many DB clients available, we don't want to choose a default for developers. Instead, the Architect SDK provides easy mechanics to parse credentials provided by the platform:

import psycopg2
import architect.sdk as architect

# Key used to cite the datastore must match the key used in your 
# architect service config
db_config = architect.datastore('primary_db')
connection = psycopg2.connect(dbname=db_config.name, 
                              user=db_config.username,
                              password=db_config.password, 
                              host=db_config.host,
                              port=db_config.port)

Events and messaging

The Architect platform also supports pub/sub based communication between services. The primary use-case for this flow would be to allow services to broadcast events for other services to subscribe to without needing to know who the subscribers are.

NOTE: As of v0.2.x of the SDK, the only method for publishing/subscribing to events using Architect is via REST (mirroring the function of traditional webhooks). We're actively working on means of supporting queuing systems like RabbitMQ, AWS SQS, and more.

Subscribing

// architect.json
{
  "subscriptions": {
    "<service_name>": {
      "<event_name>": {
        "uri": "/event/callback",
        "headers": {
          "x-custom-header": "example"
        }
      }
    }
  }
}

The URI used for registration must match a URI on your service:

from flask import Flask, request
import architect.sdk as architect

app = Flask(__name__)

@app.route("/event/callback")
def callback():
    # Custom event handling here

if __name__ == '__main__':
    app.run(host=os.environ['HOST'], port=os.environ['PORT'])

Publishing

NOTE: simple publication methods coming soon. For now, you can iterate through subscribers to submit events.

// architect.json
{
  "notifications": ["<event_name>"]
}
from requests import Request, Session
import architect.sdk as architect

# Iterate through notification subscribers to POST payload
for sub in architect.notification('<event_name>').subscriptions:
    r = requests.post('{}:{}{}'.format(sub.host, sub.port, sub.uri), data = {})

Metadata

Release files for architect.sdk 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for architect.sdk 0.2.1
File Size Uploaded
architect.sdk-0.2.1.tar.gz 4.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for architect.sdk 0.2.1
File Interpreter ABI Platform
architect.sdk-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 21.5 kB

Release files / architect.sdk-0.2.1.tar.gz

Download URL architect.sdk-0.2.1.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
62af52eb6f21cf10a39a8ff5b997492183403544a18672f76758f8431adab1c5
BLAKE2b-256 checksum
How to use checksums
43257333a860ba39be2b491b7a18fa922ac88ac4a7e1719f63617eea0270fc1e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.4

Release files / architect.sdk-0.2.1-py3-none-any.whl

Download URL architect.sdk-0.2.1-py3-none-any.whl
Size 16.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
df507e4850d188dcb303c39a253bb64028db44c40e9ab8976a19b250d5d8a177
BLAKE2b-256 checksum
How to use checksums
d37de1c77609d75ab173840e02e814e1ea6db5eafb34c09c5051bdc08efaa994
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.4

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

1 release file

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release 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