Skip to main content

Package to access and modify PTC Windchill data via the REST API

Project description

windchill-rest

windchill-rest is a Python package that provides a lightweight, object‑oriented interface to PTC Windchill’s REST API. It abstracts common REST patterns and Windchill‑specific behaviors into Python classes, allowing scripts to interact with Windchill data without dealing directly with raw REST calls.

The library is designed for automation, integration, and scripting use cases where repeatable access to Windchill objects and workflows is required.


Key Capabilities

  • Authentication and session management
    • OAuth or basic authentication
  • Automatic CSRF handling and token refresh
  • Object‑oriented access to Windchill REST resources
  • Support for common Windchill object types:
    • Parts, CAD Documents (EPMs), and Documents
    • Change objects (Problem Reports, Change Requests, Change Notices)
    • Users and Groups
  • Lifecycle and workflow actions:
    • Create, update, delete
    • Check‑in / check‑out
    • Revise
    • Set lifecycle state
  • Relationship management:
    • Part ↔ CAD document associations
    • Described‑by relationships
    • Attachments and primary content
  • File upload and download support
  • Transparent handling of paging and OData query options

Installation

Install via pip:

pip install windchill-rest

Authentication

Authentication is handled through the WcSession class. Both basic (username & password) and Oauth authentication is supported.

Basic Authentication

from windchill_rest import *

wc_session = WcSession.basic(
    wc_base_url="https://your.windchill.server/Windchill",
    username="xxxxxx",
    password="yyyyyy"
)

wc_session.authenticate()

OAuth Authentication

from windchill_rest import *

wc_session = WcSession.oauth(
    wc_base_url="https://your.windchill.server/Windchill",
    auth_url="https://your.auth.server/authorize",
    token_url="https://your.auth.server/token",
    client_id="your-client-id",
    client_secret="your-client-secret",
    redirect_uri="http://your.redirect",
    scope="Windchill.Read"
)

wc_session.authenticate()

This will:

  1. Open a browser window for authorization.
  2. Prompt you to log in and approve the application.
  3. Redirect you to a URL.
  4. Ask you to paste the redirect URL back into the console.

After authentication:

  • Access tokens and refresh tokens are stored on the session
  • CSRF headers are retrieved automatically
  • Tokens are refreshed automatically as needed

Note (Windows users):
If you encounter a SSL: CERTIFICATE_VERIFY_FAILED error during authentication, you may need to install the following package:

pip install python-certifi-win32

This ensures Python uses the Windows certificate store.


Using the Framework

Querying Objects

Objects are retrieved using get_objects, which returns a generator and transparently handles paging.

parts = wc_session.get_objects(
    WcPart,
    filter_str="Number eq '12345'",
    select_str="Number,Name,Revision"
)

for part in parts:
    print(part.attrs["Number"], part.attrs["Name"])

Supported OData options include:

  • $filter
  • $select
  • $orderby
  • $expand

Creating Objects

attrs = {
    "@odata.type": "#PTC.ProdMgmt.Part",
    "Number": "12345",
    "Name": "Example Part",
    "View": "Design",
    "Context@odata.bind": "Containers('OR:wt.pdmlink.PDMLinkProduct:123456')"
}

part = wc_session.create_object(WcPart, attrs)

Updating and Deleting Objects

part.update({
    "Name": "Updated Part Name"
})

part.delete()

Lifecycle and Check In/Out Actions

Objects that support lifecycle actions inherit from WcWorkable.

part.checkout()
part.checkin()

part.revise("B")
part.set_state("RELEASED")

Navigating Relationships

Related objects can be retrieved using navigation properties.

# Get CAD documents associated to a part
assocs = part.get_assoc_epms()

for assoc in assocs:
    print(assoc.attrs)

Managing Content

Documents support primary content and attachments.

doc = next(wc_session.get_objects(WcDoc, filter_str="Number eq 'DOC-001'"))

# Download primary content
primary = doc.get_prim_content()
file_bytes = primary.download_file()

# Add or replace primary content
doc.add_prim_content("file.pdf", file_bytes)

# Add attachment
doc.add_attachment("attachment.txt", b"example content")

Architecture Overview

The package is structured around a small set of core components:

  • WcSession
    Handles authentication, REST calls, paging, headers, and token refresh.

  • WcObj
    Base class providing CRUD operations and navigation of related objects.

  • WcWorkable
    Extends WcObj with lifecycle and check in/out behavior.

  • Domain Objects
    Windchill concepts such as Parts, Documents, CAD Documents, Change objects, Users, and Groups are modeled as Python classes with domain‑specific behavior.

This design allows scripts to operate at the object level rather than managing REST endpoints directly.


Notes and Limitations

  • Some functionality relies on Windchill REST endpoints that may not be available in all environments or may require server‑side configuration.
  • File upload logic is intentionally strict due to Windchill API requirements.
  • This package is not an official PTC SDK and is provided as‑is.

Disclaimer

This project is not affiliated with or endorsed by PTC.
Windchill is a registered trademark of PTC Inc.

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

windchill_rest-0.1.0.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

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

windchill_rest-0.1.0-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file windchill_rest-0.1.0.tar.gz.

File metadata

  • Download URL: windchill_rest-0.1.0.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for windchill_rest-0.1.0.tar.gz
Algorithm Hash digest
SHA256 43312df080e6717023a6c3c0578b1fa9d74b45e64e89e0bd36eb71ed2e50887e
MD5 f1cad11870a1804b52a5ae0418dca4a4
BLAKE2b-256 a66f0df68af7a3b602dfe5f67a689844525aab1c4b0adc428e112d334687f020

See more details on using hashes here.

File details

Details for the file windchill_rest-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: windchill_rest-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for windchill_rest-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f2579fe9fb227fd2eb8358c60d9d817ef59c7ee7114f8d8be51325d67a8cf5eb
MD5 716816f324fee23f9b47455a2cfe3a96
BLAKE2b-256 2701d8aea98203a7847792cb06d2ff0163e43b4075749660e6b2d6684cf0c9d0

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