Skip to main content

The official Python client library for the Freerouting API (api.freerouting.app), an open-source, advanced PCB (printed circuit board) auto-router

Project description

Freerouting Python Client

PyPI version License: MIT Python Versions

This library provides a convenient Python interface for interacting with the Freerouting API (api.freerouting.app). It allows you to manage routing sessions, enqueue jobs, upload designs, download results, and monitor progress programmatically.

Note: This client is currently in Alpha. The API and client library interface may change in future versions.

Links

Installation

You can install the library directly from PyPI:

pip install freerouting-client

Getting Started

You'll need an API key from the Freerouting website to use the client.

from freerouting import FreeroutingClient
import os

# --- Configuration ---
# It's recommended to use environment variables for sensitive data like API keys
api_key = os.environ.get("FREEROUTING_API_KEY")
if not api_key:
    raise ValueError("Please set the FREEROUTING_API_KEY environment variable.")

# Optional: If using a local Freerouting instance or a different API version
# base_url = "http://localhost:8080"
# version = "dev"
# client = FreeroutingClient(api_key=api_key, base_url=base_url, version=version)

# Default usage (connecting to api.freerouting.app/v1)
client = FreeroutingClient(api_key=api_key)

# --- Basic Usage ---
try:
    # Check API status
    status = client.get_system_status()
    print(f"API Status: {status.get('status', 'Unknown')}")

    # Create a session (optional, run_routing_job does this if needed)
    # session = client.create_session()
    # print(f"Created session ID: {session.get('id')}")

except Exception as e: # Consider catching specific FreeroutingError exceptions
    print(f"An error occurred: {e}")


# --- Example: Running a Full Routing Job ---
# Ensure you have a DSN file (e.g., 'my_board.dsn') available

dsn_file = "path/to/your/my_board.dsn" # CHANGE THIS PATH
job_name = "My Python Client Test Job"

if not os.path.exists(dsn_file):
    print(f"Error: Input file not found at {dsn_file}")
else:
    print(f"\nStarting routing job '{job_name}' for file '{dsn_file}'...")
    try:
        # run_routing_job handles session creation, upload, start, polling, and download
        output_data = client.run_routing_job(
            name=job_name,
            dsn_file_path=dsn_file,
            # settings={"router_passes": 5}, # Optional: Provide router settings
            poll_interval=10 # Check status every 10 seconds
            # timeout=600 # Max wait time in seconds (default 3600)
        )

        print("Job completed successfully!")

        # The output_data contains the result, including the base64 encoded SES file
        output_filename = output_data.get("filename", "routed_output.ses")
        output_filepath = f"./{output_filename}" # Save in current directory

        # Decode and save the output .ses file
        if "data" in output_data:
            import base64
            with open(output_filepath, "wb") as f:
                f.write(base64.b64decode(output_data["data"]))
            print(f"Output saved to: {output_filepath}")
        else:
            print("Warning: Output data field missing in response.")
        # print("Full output response:", output_data)

    except Exception as e: # Replace with specific exceptions if defined
        print(f"Routing job failed: {e}")

Contributing

Contributions to the Freerouting Python Client are welcome! Please refer to the main Freerouting Contribution Guide for general guidelines and open an issue or pull request in this repository (freerouting-python-client).

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

🙏 Support the Main Freerouting Project

Developing and maintaining Freerouting requires significant effort. If you find the tool useful, please consider supporting its development!

Sponsor @andrasfuchs on GitHub Sponsors

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

freerouting_client-2.1.0.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

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

freerouting_client-2.1.0-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file freerouting_client-2.1.0.tar.gz.

File metadata

  • Download URL: freerouting_client-2.1.0.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for freerouting_client-2.1.0.tar.gz
Algorithm Hash digest
SHA256 4e242c5f3a0eaca6e4c3cdaf4e5d6798d449c623a2fd64d94ac9008675261c6b
MD5 6591e586c4809990273d336e1ee559f6
BLAKE2b-256 2e19a625cb34d0cb9bfb670d74154915f89138c8c5cb42b45f73b8a59b8381ee

See more details on using hashes here.

File details

Details for the file freerouting_client-2.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for freerouting_client-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a40aeefcbbde30b221e5686669f11a3ffc521117420ae251b6053cd9daa791fe
MD5 f67f1605d71c7bda6e8d8dfd4cd0a577
BLAKE2b-256 d897fc91921a4af47f473d6cbc107279bb115df561a482ab31e147b9fcfb7e70

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