Python Client for the Canopy Simulation API
Project description
Introduction
This package is designed for customers of Canopy Simulations who would like to access the Canopy API from Python, for example using Jupyter Notebooks.
Currently the library is split into two parts:
-
The client generated using the Swagger toolset is located in the "canopy/swagger" folder. We don't have a great deal of control over how this code looks, but it should give a fairly complete interface to the main API.
-
One folder up from that in the "canopy" folder we are adding helper functions which wrap common use cases in simple functions. You can also use these functions as a reference to using the swagger generated code.
When using the library you generally start by creating a canopy.Session
object.
The session object manages authentication, and the caching of user settings.
Calling session.authentication.authenticate()
before calling Swagger generated client functions ensures that you are
authenticated and that any expired access tokens are refreshed.
Our helper functions will generally handle calling authenticate before making any calls.
Once you have created a session you can pass the session.client
into the swagger generated client code as the api_client
parameter.
The canopy/load_study_job_data.py
function shows all this being done.
The following example shows how to create a session and request some output channels from a study using our helper function:
import canopy
session = canopy.Session(client_id='<your_client_id>', user_name='<your_username>')
study_data = canopy.load_study_data(session, '<study_id>', 'DynamicLap', ['sRun', 'vCar'])
When running this code you will be prompted for your client secret (which you can request from us) and your password if
it is the first time session.authentication.authenticate()
has been called for this session instance.
Requirements.
This has currently been tested on Python 3.6 and higher.
Installation & Usage
pip install
pip install canopy
You may need to run pip
with root permission: sudo pip install canopy
.
From a Jupyter Notebook you can run !pip install canopy
.
Setuptools
Install via Setuptools.
python setup.py install --user
(or sudo python setup.py install
to install the package for all users)
Getting Started
See canopy/__main__.py
for example usage.
Updating the Swagger Client
The Swagger generated part of this library may occasionally need to be regenerated as the Canopy API is updated.
Due to a bug in the python code generator
we cannot generate the client from the public API. Instead we can update the repository file canopy-swagger-no-allof.json
to
contain the latest swagger definition with the allOf
references removed and generate from that.
Currently the easiest way to do this is with access to the Canopy source code, which is internal to Canopy. Therefore if you believe the Swagger client requires updating you should ask us to update this library.
For Canopy employees: To remove allOf
references, comment out the line c.SchemaFilter<FixReadOnlyRefSchemaFilter>();
in
Canopy.Api.Swagger.SwaggerConfig
, run locally, copy the output of https://localhost:44300/swagger/docs/v1
, and then discard
the changes to Canopy.Api.Swagger.SwaggerConfig
.
Once you have an up to date canopy-swagger-no-allof.json
file you can use the Dockerfile in this repository to
create a docker image to generate the new API stubs:
docker image build -t canopy-python-gen:1 .
docker container run -i -t --mount type=bind,src='c:\dev\canopy\canopy-python',dst=/usr/src/app/repo canopy-python-gen:1 /bin/bash
java -jar swagger-codegen-cli.jar generate -l python -i ./canopy-swagger-no-allof.json -o ./gen -DpackageName="canopy.swagger"
rsync -av gen/canopy.swagger/ gen/canopy/swagger/
rm -r repo/canopy/swagger
rm -r repo/docs
cp -r gen/canopy/swagger repo/canopy
cp -r gen/docs repo
Documentation for API Endpoints
All URIs are relative to https://api.canopysimulations.com
Class | Method | HTTP request | Description |
---|---|---|---|
AccountSettingsApi | account_settings_get | GET /account-settings/{tenantId}/{userId} | |
AccountSettingsApi | account_settings_put | PUT /account-settings/{tenantId}/{userId} | |
AvailabilityApi | availability_get | GET /Availability | |
AvailabilityApi | availability_head | HEAD /Availability | |
ConfigApi | config_decrypt | POST /configs/decrypt | |
ConfigApi | config_delete_config | DELETE /configs/{tenantId}/{configId} | |
ConfigApi | config_delete_config_deprecated | DELETE /configs/{tenantId}/{userId}/{configId} | |
ConfigApi | config_encrypt | POST /configs/encrypt | |
ConfigApi | config_get_config | GET /configs/{tenantId}/{configId} | |
ConfigApi | config_get_config_deprecated | GET /configs/{tenantId}/{userId}/{configId} | |
ConfigApi | config_get_config_names | GET /configs/{tenantId}/names | |
ConfigApi | config_get_config_versions | GET /configs/{tenantId}/{configId}/versions | |
ConfigApi | config_get_config_versions_deprecated | GET /configs/{tenantId}/{userId}/{configId}/versions | |
ConfigApi | config_get_config_without_user_id_deprecated | GET /configs/{tenantId}/auto/{configId} | |
ConfigApi | config_get_configs | GET /configs/{tenantId} | |
ConfigApi | config_post_config | POST /configs/{tenantId} | |
ConfigApi | config_post_config_deprecated | POST /configs/{tenantId}/{userId} | |
ConfigApi | config_post_configs | POST /configs/{tenantId}/batch | |
ConfigApi | config_post_configs_deprecated | POST /configs/{tenantId}/{userId}/batch | |
ConfigApi | config_put_config | PUT /configs/{tenantId}/{configId} | |
ConfigApi | config_put_config_deprecated | PUT /configs/{tenantId}/{userId}/{configId} | |
ConfigApi | config_put_config_owner | PUT /configs/{tenantId}/{configId}/owner | |
ConfigApi | config_upgrade_config | POST /configs/upgrade/{tenantId}/{targetSimVersion} | |
ConfigApi | config_upgrade_config_deprecated | POST /configs/upgrade/{targetSimVersion} | |
EndToEndTestInboxApi | end_to_end_test_inbox_get_latest_message_and_clear_mailbox | GET /test-mailboxes/{mailboxName} | |
ListFilterApi | list_filter_upgrade_list_filter | GET /list-filters/upgrade | |
MembershipApi | membership_delete_refresh_tokens | DELETE /membership/refresh-tokens/{tenantId}/{userId} | |
MembershipApi | membership_get_password_reset_token_validity | GET /membership/password-reset-tokens/{userId} | |
MembershipApi | membership_get_user_roles | GET /membership/roles/{tenantId}/{userId} | |
MembershipApi | membership_post_identified_user | POST /membership/identified-users | |
MembershipApi | membership_post_initialize | POST /membership/initialize | |
MembershipApi | membership_post_password_reset_confirmation | POST /membership/password-reset-confirmations | |
MembershipApi | membership_post_password_reset_request | POST /membership/password-reset-requests | |
MembershipApi | membership_post_registration | POST /membership/registrations | |
MembershipApi | membership_put_user_role | PUT /membership/roles/{tenantId}/{userId} | |
PoolApi | pool_get_pool_status | GET /pools/{tenantId} | |
PoolApi | pool_get_pools | GET /pools | |
PoolApi | pool_get_test_auto_scale_formula | GET /pools/autoscale/test | |
SimVersionApi | sim_version_get_document | GET /sim-versions/{simVersion}/documents/{documentPath} | |
SimVersionApi | sim_version_get_documents | GET /sim-versions/{simVersion}/documents | |
SimVersionApi | sim_version_get_sim_version | GET /sim-versions/current | |
SimVersionApi | sim_version_get_wiki_document | GET /sim-versions/{wikiVersion}/wiki/{documentPath} | |
SimVersionApi | sim_version_post_sim_version | POST /sim-versions/current | |
StudyApi | study_delete_study | DELETE /studies/{tenantId}/{studyId} | |
StudyApi | study_delete_study_deprecated | DELETE /studies/{tenantId}/{userId}/{studyId} | |
StudyApi | study_get_all_tenants_study_statistics | GET /studies/statistics | |
StudyApi | study_get_sim_type | GET /studies/types/sims/{simType} | |
StudyApi | study_get_studies | GET /studies/{tenantId} | |
StudyApi | study_get_study | GET /studies/{tenantId}/{studyId} | |
StudyApi | study_get_study_deprecated | GET /studies/{tenantId}/{userId}/{studyId} | |
StudyApi | study_get_study_download | GET /studies/{tenantId}/{studyId}/download | |
StudyApi | study_get_study_download_deprecated | GET /studies/{tenantId}/{userId}/{studyId}/download | |
StudyApi | study_get_study_download_url | GET /studies/{tenantId}/{studyId}/download-url | |
StudyApi | study_get_study_download_url_deprecated | GET /studies/{tenantId}/{userId}/{studyId}/download-url | |
StudyApi | study_get_study_job | GET /studies/{tenantId}/{studyId}/jobs/{jobId} | |
StudyApi | study_get_study_job_deprecated | GET /studies/{tenantId}/{userId}/{studyId}/jobs/{jobId} | |
StudyApi | study_get_study_job_download | GET /studies/{tenantId}/{studyId}/jobs/{jobId}/download | |
StudyApi | study_get_study_job_download_deprecated | GET /studies/{tenantId}/{userId}/{studyId}/jobs/{jobId}/download | |
StudyApi | study_get_study_job_metadata | GET /studies/{tenantId}/{studyId}/jobs/{jobId}/metadata | |
StudyApi | study_get_study_job_metadata_deprecated | GET /studies/{tenantId}/{userId}/{studyId}/jobs/{jobId}/metadata | |
StudyApi | study_get_study_jobs | GET /studies/{tenantId}/{studyId}/jobs | |
StudyApi | study_get_study_jobs_deprecated | GET /studies/{tenantId}/{userId}/{studyId}/jobs | |
StudyApi | study_get_study_metadata | GET /studies/{tenantId}/{studyId}/metadata | |
StudyApi | study_get_study_metadata_deprecated | GET /studies/{tenantId}/{userId}/{studyId}/metadata | |
StudyApi | study_get_study_metadata_without_user_id_deprecated | GET /studies/{tenantId}/auto/{studyId}/metadata | |
StudyApi | study_get_study_type | GET /studies/types/{studyType} | |
StudyApi | study_get_study_types | GET /studies/types | |
StudyApi | study_get_study_without_user_id_deprecated | GET /studies/{tenantId}/auto/{studyId} | |
StudyApi | study_get_tenant_access_information | GET /studies/{tenantId}/access | |
StudyApi | study_get_tenant_billable_stored_simulation_count | GET /studies/statistics/stored/{tenantId} | |
StudyApi | study_get_tenant_study_statistics | GET /studies/statistics/{tenantId} | |
StudyApi | study_merge_study | PATCH /studies/{tenantId}/{studyId}/merge | |
StudyApi | study_merge_study_deprecated | PATCH /studies/{tenantId}/{userId}/{studyId}/merge | |
StudyApi | study_post_study | POST /studies/{tenantId} | |
StudyApi | study_post_study_deprecated | POST /studies/{tenantId}/{userId} | |
StudyApi | study_put_config_owner | PUT /studies/{tenantId}/{studyId}/owner | |
StudyApi | study_put_study | PUT /studies/{tenantId}/{studyId} | |
StudyApi | study_put_study_deprecated | PUT /studies/{tenantId}/{userId}/{studyId} | |
SupportSessionApi | support_session_get_all_support_sessions | GET /support-sessions/all | |
SupportSessionApi | support_session_get_support_session | GET /support-sessions/{tenantId}/{documentId} | |
SupportSessionApi | support_session_get_support_session_deprecated | GET /support-sessions/{tenantId}/{userId}/{documentId} | |
SupportSessionApi | support_session_put_support_session | PUT /support-sessions/{tenantId}/{documentId} | |
SupportSessionApi | support_session_put_support_session_deprecated | PUT /support-sessions/{tenantId}/{userId}/{documentId} | |
TenancyApi | tenancy_get_tenant | GET /tenants/{tenantId} | |
TenancyApi | tenancy_get_tenant_users | GET /tenants/{tenantId}/users | |
TenancyApi | tenancy_get_tenants | GET /tenants | |
TenancyApi | tenancy_post_tenant | POST /tenants | |
TenancyApi | tenancy_put_tenant | PUT /tenants/{tenantId} | |
TenantSettingsApi | tenant_settings_get_admin_tenant_settings | GET /tenant-settings/admin/{tenantId} | |
TenantSettingsApi | tenant_settings_get_tenant_channel_import_mappings | GET /tenant-settings/channel-import-mappings/{tenantId} | |
TenantSettingsApi | tenant_settings_get_tenant_default_custom_property_names | GET /tenant-settings/default-custom-property-names/{tenantId} | |
TenantSettingsApi | tenant_settings_get_tenant_settings_sim_version | GET /tenant-settings/sim-version/{tenantId} | |
TenantSettingsApi | tenant_settings_get_tenant_worksheet_label_definitions | GET /tenant-settings/worksheet-label-definitions/{tenantId} | |
TenantSettingsApi | tenant_settings_put_admin_tenant_settings | PUT /tenant-settings/admin/{tenantId} | |
TenantSettingsApi | tenant_settings_put_tenant_channel_import_mappings | PUT /tenant-settings/channel-import-mappings/{tenantId} | |
TenantSettingsApi | tenant_settings_put_tenant_default_custom_property_names | PUT /tenant-settings/default-custom-property-names/{tenantId} | |
TenantSettingsApi | tenant_settings_put_tenant_settings_sim_version | PUT /tenant-settings/sim-version/{tenantId} | |
TenantSettingsApi | tenant_settings_put_tenant_worksheet_label_definitions | PUT /tenant-settings/worksheet-label-definitions/{tenantId} | |
UserSettingsApi | user_settings_get_user_settings | GET /user-settings/{tenantId}/{userId} | |
UserSettingsApi | user_settings_put_user_settings | PUT /user-settings/{tenantId}/{userId} | |
WorksheetApi | worksheet_get_worksheet | GET /worksheets/{tenantId}/{worksheetId} | |
WorksheetApi | worksheet_post_duplicate_configs | POST /worksheets/{tenantId}/{worksheetId}/duplicate | |
WorksheetApi | worksheet_post_worksheet | POST /worksheets/{tenantId} | |
WorksheetApi | worksheet_put_worksheet | PUT /worksheets/{tenantId}/{worksheetId} |
Documentation For Models
- AdditionalTests
- AdminTenantSettings
- AdminTenantSettingsBuilder
- AutoScaleRun
- AutoScaleRunError
- AvailabilityResult
- BatchCreateConfigsResult
- BlobAccessInformation
- CanopyDocument
- ChannelImportMapping
- ChannelSettings
- ChartSettings
- CollatedLabelDefinitions
- CollatedWorksheetLabels
- ComputeNodeResult
- ConfigColumnLabelDefinitions
- ConfigHash
- ConfigOwnerData
- ConfigReference
- ConfigResolvedLabels
- ConfigResolvedReference
- ConfigResolvedReferenceData
- ConfigTypeDefinition
- DefaultConfigId
- DefaultConfigReference
- DefaultCustomPropertyNames
- DocumentCustomPropertyData
- DocumentCustomPropertyGroup
- DocumentGroupResult
- DocumentId
- DocumentName
- DocumentNameResult
- DocumentSubType
- DocumentTypeCustomPropertyGroups
- DocumentUserInformation
- DocumentsAndContinuationToken
- DuplicateConfigsData
- DuplicateConfigsResult
- GetAccountSettingsResult
- GetAdminTenantSettingsQueryResult
- GetAllSupportSessionsQueryResult
- GetAllTenantsStudyStatisticsQueryResult
- GetConfigNamesQueryResult
- GetConfigQueryResult
- GetConfigVersionsQueryResult
- GetConfigsQueryResult
- GetPoolStatusQueryResult
- GetPoolsItem
- GetPoolsItemInterval
- GetPoolsQueryResult
- GetSimVersionDocumentQueryResult
- GetSimVersionDocumentsQueryResult
- GetStudiesQueryResult
- GetStudyDownloadUrlQueryResult
- GetStudyJobMetadataQueryResult
- GetStudyJobQueryResult
- GetStudyJobsQueryResult
- GetStudyQueryResult
- GetStudyTypesQueryResult
- GetSupportSessionQueryResult
- GetTenantAccessInformationQueryResult
- GetTenantBillableStoredSimulationCountQueryResult
- GetTenantChannelImportMappingsQueryResult
- GetTenantDefaultCustomPropertyNamesQueryResult
- GetTenantQueryResult
- GetTenantSettingsSimVersionQueryResult
- GetTenantStudyStatisticsQueryResult
- GetTenantUsersQueryResult
- GetTenantUsersQueryResultUserItem
- GetTenantWorksheetLabelDefinitionsQueryResult
- GetTenantsQueryResult
- GetTenantsQueryResultTenantItem
- GetUserRolesQueryResult
- GetUserSettingsQueryResult
- GetWikiDocumentQueryResult
- GetWorksheetQueryResult
- IPreviousDefinitionSimTypeDefinition
- IPreviousDefinitionStudyTypeDefinition
- IdentifiedUserData
- LabelDefinition
- LabelDefinitions
- ListFilter
- ListFilterCondition
- ListFilterGroup
- NameValuePair
- NewBatchConfigData
- NewConfigData
- NewSimVersionData
- NewStudyData
- NewStudyDataSource
- NewTenantData
- NewWorksheetData
- PasswordResetConfirmationData
- PasswordResetRequestData
- PoolId
- PoolSettings
- PostStudyResult
- RegistrationData
- ResolvedLabel
- ResolvedStatisticLabel
- SimTypeDefinition
- SimTypeInputTelemetryChannel
- SimTypeInputTelemetryChannels
- SimTypeInputTelemetryEvaluatedChannel
- SimTypeInputTelemetryEvaluatedChannelSuffix
- SimVersion
- SimVersionDocumentNameResult
- SimulationColumnLabelDefinitions
- SimulationInput
- SimulationResolvedLabels
- StudyBlobAccessInformation
- StudyDocument
- StudyDocumentStudyDocumentDataSource
- StudyDocumentsAndContinuationToken
- StudyInputHash
- StudyInputHashes
- StudyJobDocumentsAndContinuationToken
- StudyReference
- StudyResolvedLabels
- StudyResolvedReference
- StudyResolvedReferenceData
- StudyTypeDefinition
- SupportSession
- SupportSessionData
- SupportSessionResponse
- TenantConfigReference
- TenantDefaultCustomPropertyNames
- TenantDocumentDatabaseId
- TenantId
- TenantInformation
- TenantName
- TenantStatistics
- TestAutoScaleFormulaQueryResult
- TextDocument
- TextDocumentOptionalContent
- UpdatedAccountSettings
- UpdatedAdminTenantSettings
- UpdatedChannelImportMappings
- UpdatedConfigData
- UpdatedStudyData
- UpdatedTenantData
- UpdatedTenantDefaultCustomPropertyNames
- UpdatedTenantSettingsSimVersion
- UpdatedUserSettings
- UpdatedWorksheetData
- UpdatedWorksheetLabelDefinitions
- UpgradeConfigData
- UpgradeConfigQueryResult
- UserId
- UserInformation
- UserRoleData
- UserSettings
- UserSettingsBuilder
- Username
- ValidDocumentCustomPropertyName
- VersionedDocumentMetadata
- Worksheet
- WorksheetConfig
- WorksheetOutline
- WorksheetResolvedReferences
- WorksheetRow
- WorksheetStudy
Documentation For Authorization
- Type: OAuth
- Flow: password
- Authorization URL: https://api.canopysimulations.com/token
- Scopes: N/A
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.