Skip to main content

A Python API for building models in OnShape

Project description

OnPy

CI Tests MIT License PyPi Version black

Overview

OnPy is a high level Python interface for building 3D models in Onshape

In OnPy you can:

  • Build 2D sketches
  • Extrude to create 3D geometries
  • Interface with other OnShape features

Installation & Authentication

You can install OnPy with pip:

pip install onpy

The first time you run OnPy, you will need to load your OnShape developer keys. OnPy will automatically prompt you the first time it runs. You can trigger this dialogue with:

$ python -c "from onpy import Client;Client()"

Then, you can provide your keys:

$ python -c "from onpy import Client;Client()"

OnPy needs your OnShape credentials.
navagate 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 - The developer secret key
  • ONSHAPE_DEV_ACCESS - The developer "access" key

Usage

[In depth guide coming soon]

What is OnPy for?

OnPy's primary purpose is to mock the workflow of a typical parametric cad program through Python. This allows tools like LLMs and automation products to interface with OnShape.

OnShape natively supports FeatureScript; an OnShape native scripting language used for defining OnShape features. FeatureScript is a vastly powerful tool—many of it's strengths are leveraged in this package. However, FeatureScript is created to define individual features; there is no way to parametrically generate a design with it.

Instead, OnPy interfaces with OnShape's APIs to create designs that function the same as ones generated in the web ui.

Syntax Overview

The following is from examples/cylinder.py :

import onpy

# we'll create a new document, then reference the default partstudio
document = onpy.create_document("Cylinder Example")
partstudio = document.get_partstudio()

# now, we'll define a sketch
sketch = partstudio.add_sketch(
    plane=partstudio.features.top_plane,  # we define the plane to draw on
    name="New Sketch",  # and we name the sketch
)

# in this new sketch, we'll draw a circle
sketch.add_circle(center=(0, 0), radius=0.5)  # the default units are inches

# next, we'll extrude the sketch. the syntax is similar
extrude = partstudio.add_extrude(
    faces=sketch,  # we'll extrude the entire sketch ...
    distance=1,  # ... by one inch
)

If we look in our browser, we'll see a new document aptly named "Cylinder Example."

A screenshot of the code output

User Guide

For a more in-depth guide on how to use OnPy, view the user guide. This gives a detailed explanation on how to use all of OnPy's features.

Contributing

OnPy is obviously in it's earliest stage. All contributors are gratefully welcomed.

This module is structured to be as idiomatic as possible, while also following some of OnShape's layout quirks. There is no strict rules for this repository, but it's a good idea to try to stick with the flow of other things.

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

onpy-0.0.6.tar.gz (1.1 MB view details)

Uploaded Source

Built Distribution

onpy-0.0.6-py3-none-any.whl (46.6 kB view details)

Uploaded Python 3

File details

Details for the file onpy-0.0.6.tar.gz.

File metadata

  • Download URL: onpy-0.0.6.tar.gz
  • Upload date:
  • Size: 1.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for onpy-0.0.6.tar.gz
Algorithm Hash digest
SHA256 ee659e0c45aac9796deb1bc856eab3414e235d9df087e9486385b21543db0c00
MD5 644c4067dd3d7a7fcda99759ef34bd76
BLAKE2b-256 77af4a3e81a4d84b9163649ec3915c757903a224bbcfb1db95a1d02620f9ea6b

See more details on using hashes here.

File details

Details for the file onpy-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: onpy-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 46.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for onpy-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 82434676847f5a5283dc80664f3160def301c36a5ff5a73b45c92515d2ebca70
MD5 fa5f177660038a8d196a4b9a0d7bb7bc
BLAKE2b-256 0ecb355f795880c90a5d425c556202f7958cbdc940df63ccdb196fa1c627eda3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page