A Python API for building models in OnShape
Project description
OnPy
Overview
OnPy is an unofficial Python API for building 3D models in Onshape.
With OnPy, you can:
- Build 2D sketches
- Extrude to create 3D geometries
- Interface with other Onshape features
Installation & Authentication
Install OnPy using pip:
pip install onpy
The first time you run OnPy, you will need to load your Onshape developer keys. OnPy will automatically prompt you for these keys. You can trigger this dialogue manually with:
python -c "from onpy import Client; Client()"
You’ll then be prompted to provide your keys:
OnPy needs your Onshape credentials.
Navigate to https://dev-portal.onshape.com/keys and generate a pair of access & secret keys. Paste them here when prompted:
Secret key: ...
Access key: ...
Alternatively, you can set your Onshape keys as environment variables:
ONSHAPE_DEV_SECRET- Your developer secret keyONSHAPE_DEV_ACCESS- Your developer access key
What is OnPy for?
OnPy is a high-level Python API for Onshape. It enables third-party apps to use the same features as the Onshape modeler directly from Python.
Onshape natively supports FeatureScript, a scripting language for defining Onshape features. FeatureScript is powerful, and many of its strengths are leveraged in this package. However, it is designed to define individual features and cannot parametrically generate entire designs.
OnPy bridges this gap by interfacing with Onshape's APIs to create designs equivalent to those made in the web UI.
Disclaimer
OnPy connects to your Onshape account using developer keys that you provide, which are generated via Onshape's developer portal. By generating and using these keys, you agree to Onshape's Terms of Use.
When using OnPy, all API calls to Onshape are made on your behalf. As a user, you are responsible for adhering to Onshape's Terms of Use and accept full accountability for any actions taken through OnPy.
OnPy is provided "as is," without warranty of any kind, either express or implied. It assumes no responsibility for any violations of Onshape's Terms of Use arising from its use. Additionally, OnPy is not liable for any consequences, damages, or losses resulting from misuse of the API or non-compliance with Onshape's Terms of Use.
By using OnPy, you agree to these terms and accept all associated risks and liabilities.
Syntax Overview
The following example is from examples/cylinder.py:
import onpy
# Create a new document, then reference the default Part Studio
document = onpy.create_document("Cylinder Example")
partstudio = document.get_partstudio()
# Define a sketch
sketch = partstudio.add_sketch(
plane=partstudio.features.top_plane, # Define the plane to draw on
name="New Sketch", # Name the sketch
)
# Draw a circle in the sketch
sketch.add_circle(center=(0, 0), radius=0.5) # Default units are inches
# Extrude the sketch
extrude = partstudio.add_extrude(
faces=sketch, # Extrude the entire sketch ...
distance=1, # ... by one inch
)
After running the above code, you’ll see a new document in your browser, aptly named "Cylinder Example."
User Guide
For a more in-depth guide on how to use OnPy, refer to the user guide. It provides a detailed explanation of all of OnPy's features.
Contributing
OnPy is still in its earliest stages, and all contributions are welcome.
This module is designed to be as idiomatic as possible while following some of Onshape's layout quirks. There are no strict rules for contributing, but it’s a good idea to align with the existing structure.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file onpy-0.0.7.tar.gz.
File metadata
- Download URL: onpy-0.0.7.tar.gz
- Upload date:
- Size: 1.1 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23d5cf03e516ec502db4485cef70424e5627751e2f80c32b45d394f1ceb6f412
|
|
| MD5 |
68375a5c6811997c52f764f673188dba
|
|
| BLAKE2b-256 |
d45893e70b8d16cd93c0a593107ecdb8c98516d232eda20f3add7216edd66925
|
File details
Details for the file onpy-0.0.7-py3-none-any.whl.
File metadata
- Download URL: onpy-0.0.7-py3-none-any.whl
- Upload date:
- Size: 48.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f055bdb7dc448eb338d7ff687148bd9e110989d0d40119028482aa37c37c01cd
|
|
| MD5 |
69977f45fb56259b09da4793f55f1207
|
|
| BLAKE2b-256 |
566561b91852e145818049f75a6e7ddb811c6bb7164fad47f6552e0c36d675d4
|