https://github.com/3scale-qe/3scale-api-python
3scale API Python Client
https://github.com/3scale-qe/3scale-api-python
3scale api pipenv python
Last synced: 5 months ago
JSON representation
3scale API Python Client
- Host: GitHub
- URL: https://github.com/3scale-qe/3scale-api-python
- Owner: 3scale-qe
- License: apache-2.0
- Created: 2019-03-05T08:30:06.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2025-12-06T03:17:02.000Z (6 months ago)
- Last Synced: 2025-12-21T22:32:12.690Z (6 months ago)
- Topics: 3scale, api, pipenv, python
- Language: Python
- Homepage:
- Size: 418 KB
- Stars: 5
- Watchers: 3
- Forks: 20
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 3scale REST API client in Python
3Scale REST API client in a wrapper over the 3scale API.
[](https://github.com/3scale-qe/3scale-api-python/actions)
## Installing
Install and update using pip:
```bash
pip install 3scale-api
```
Or as a dependency using the pipenv
```bash
pipenv install 3scale-api
```
## Usage
Client supports basic CRUD operations and it using the official 3scale API.
The API can be found at `/p/admin/api_docs`
Basic usage of the client:
```python
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:
```bash
pipenv install --dev
```
and then run the `pytest`:
```bash
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=''
# OPTIONAL:
THREESCALE_MASTER_URL='https://master.3scale.net'
THREESCALE_MASTER_TOKEN=''
```