Skip to main content

3scale API python client

Project description

3scale REST API client in Python

3Scale REST API client in a wrapper over the 3scale API.

Build status: CircleCI

Installing

Install and update using pip:

pip install 3scale-api

Or as a dependency using the pipenv

pipenv install 3scale-api

Usage

Client supports basic CRUD operations and it using the official 3scale API.

The API can be found at <https://yourdomain-admin.3scale.net>/p/admin/api_docs

Basic usage of the client:

from threescale_api import ThreeScaleClient, resources
from typing import List

client = ThreeScaleClient(url="myaccount.3scale.net", token="secret_token", ssl_verify=True)

# Get list of APIs/Services or any other resource
services: List[resources.Service] = client.services.list()

# Get service by it's name
test_service: resources.Service = client.services["test_service"] # or use: client.services.read_by_name(system_name)

# Get service by it's id
test_service: resources.Service = client.services[12345] # or use client.services.read(id)

# To get raw JSON response - you can use the fetch method - it takes the service id
raw_json: dict = client.services.fetch(12345)

# To create a new service (or any other resource), parameters are the same as you would provide by the documentation
new_service: resources.Service = client.services.create(system_name='my_testing_service', name="My Testing service")

# In order to update service you can either
client.services[123456].update(param="new_value")
# or
service: resources.Service = client.services[123456]
service['param'] = 'new_value'
service.update()

# To get a proxy config you can use
proxy: resources.Proxy = client.services['test_service'].proxy.read()

# To update the proxy you can either
proxy: resources.Proxy = client.services['test_service'].proxy.update(parameter_to_update='update')
# or
proxy_instance = client.services['test_service'].proxy.read()
proxy_instance['param'] = 'new_value'
proxy_instance.update()

# On the service you can access the:
service: resources.Service = client.services[123456]
service.proxy           # The PROXY client
service.mapping_rules   # mapping rules client
service.metrics         # metrics
service.app_plans       # application plans

# The proxy supports:
proxy = service.proxy.read()
proxy.promote(version=1, from_env="sandbox", to_env="production") # The promote operation
proxy.mapping_rules # The mapping rules
proxy.configs       # proxy configurations client
proxy.policies      # Policies defined for the API

Run the Tests

To run the tests you need to have installed development dependencies:

pipenv install --dev

and then run the pytest:

pipenv run pytest -v

Integration tests configuration

To run the integration tests you need to set these env variables:

THREESCALE_PROVIDER_URL='https://example-admin.3scale.net'
THREESCALE_PROVIDER_TOKEN='<test-token>'

# OPTIONAL:
THREESCALE_MASTER_URL='https://master.3scale.net'
THREESCALE_MASTER_TOKEN='<test-master-token>'

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

3scale-api-0.11.0.tar.gz (26.5 kB view details)

Uploaded Source

Built Distribution

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

3scale_api-0.11.0-py3-none-any.whl (38.1 kB view details)

Uploaded Python 3

File details

Details for the file 3scale-api-0.11.0.tar.gz.

File metadata

  • Download URL: 3scale-api-0.11.0.tar.gz
  • Upload date:
  • Size: 26.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.1.3 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.4

File hashes

Hashes for 3scale-api-0.11.0.tar.gz
Algorithm Hash digest
SHA256 ebeae254d177dd614a29d90ea92c7deffe87a67a3f51d47b88f999267406506f
MD5 9a8355de6da40f1e60cd879a5c0e4f15
BLAKE2b-256 c809360fa07ab65f2657591c467ab2f0f258f2f28ea76c811fb1acb02c4ca21a

See more details on using hashes here.

File details

Details for the file 3scale_api-0.11.0-py3-none-any.whl.

File metadata

  • Download URL: 3scale_api-0.11.0-py3-none-any.whl
  • Upload date:
  • Size: 38.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.1.3 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.4

File hashes

Hashes for 3scale_api-0.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e14b35b6e8a72497d569e696fda9465d74ec41dc1068a815670fb5dddfa4d36a
MD5 069301ca9da55a84c374ce412d356fa7
BLAKE2b-256 e56483e21c32e14b5cea9c12774ecc2716a9355e1db8952d5cef38d3ad191aa2

See more details on using hashes here.

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