Skip to main content

Python client library for the Hudu API

Reason this release was yanked:

Yanked- this was Pre-Versioning Convention

Project description

hudu-magic

Publish to PyPI

PyWheels PyPi

A tiny, enum-driven, class-based Python API client for Hudu.

  • Minimal dependencies (requests)
  • Generated from OpenAPI
  • Low Maintenance
  • Designed for clarity and maintainability

Quick Start

from hudu_magic import HuduClient

client = HuduClient(
    api_key="your_api_key",
    instance_url="https://yourinstance.huducloud.com"
)

company = client.companies.create(name="Test Company")

# Use a real asset_layout_id from your Hudu instance (e.g. from client.asset_layouts.list()).
asset = client.assets.create(
    company_id=company.id,
    name="Router",
    asset_layout_id=1,
)

asset.name = "Updated Router"
asset.save()

asset.delete()

Installation

Install package

pip install hudu-magic

Usage Info and Guide

There are several examples in the examples folder that might be helpful if you're just starting out

Core Concepts

Client

Handles auth, requests, pagination, wrapping.

client.assets.list()

Collections

Collection-level operations:

  • list()
  • get()
  • create()
  • delete()
  • archive()
  • unarchive()
assetsforcompany.save()
assetsforcompany.delete()
assetsforcompany.archive()

Models (HuduObject)

Instance-level operations:

  • save()
  • delete()
  • refresh()
  • relate_to()
  • list_photos()
  • list_uploads()
  • relate_to()
  • upload_to()
asset.save()
asset.delete()

Special Model Methods

Companies

mycompany.list_assets()
mycompany.list_articles()
mycompany.list_passwords()
mycompany.list_procedures()
mycompany.list_websites()
mycompany.create_website()

Creating Objects

The create base method for all objects is simple. you can specify properties in either the payload object (standard dictionary) or as kwargs (just propertyname=value)

This means you can use either:

kwargs (recommended)

client.assets.create(name="Router", company_id=1, asset_layout_id=10)

dict payload

client.assets.create(payload={"name": "Router", "company_id": 1, "asset_layout_id": 10})

Updating Objects

asset.name = "New Name"
asset.save()

or

asset.update(name="New Name")

Relations

asset.relate_to(website)

or

client.relations.create(from_obj=asset, to_obj=website)

Uploads

asset.upload_to("file.zip")

uploads = asset.list_uploads()

Photos

asset.add_photo("image.png")

photos = asset.list_photos()

Generating builds for new Hudu versions or previous versions

  1. Place openapi spec file https://yoururl.huducloud.com/api-docs.json in project directory as hudu-openapiv1.json

  2. run python generate_endpoints.py after sourcing virtual environment (that has dev dependencies installed)

  3. run ./build.sh

todo: .\build.ps1

this is designed to be super simple so that subsequent releases can eventually just be automatically generated, tested, validated, and pushed to pypi.

Note on building and tests

  • Run tests with ./build.sh --test (or pytest from a dev environment with pip install -e ".[dev]").
  • Integration tests are skipped unless you set HUDU_RUN_INTEGRATION=1. With that set, copy testenv.example to testenv and fill in HUDU_TEST_API_KEY and HUDU_TEST_INSTANCE.

Error Handling, Additional Info / Help

If more information is needed, you can call this method on class members to get all associated info from hudu's API spec-

huduobject.help()

For resources such as client.assets, you can call:

client.assets.describe()

or for more verbose info:

client.assets.help()

if an object type or resource doesnt support a method call or payload param, you'll be notified of which one(s), if any, are invalid.

Special Class Methods

Advanced Use Possibilities

Multi-Client

You can instantiate two or more client objects, like above, to transfer data from, say, your dev instance to production. This hasn't been extensively tested expecially for objects dependent on companies (assets, passwordfolders)

client2.assets.create(
    **client1.assets.get(6).to_dict()
)

Philosophy

  • Simple > clever
  • Explicit > implicit
  • Thin wrapper over Hudu API

License

MIT

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

hudu_magic-0.1.26.tar.gz (40.7 kB view details)

Uploaded Source

Built Distribution

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

hudu_magic-0.1.26-py3-none-any.whl (42.3 kB view details)

Uploaded Python 3

File details

Details for the file hudu_magic-0.1.26.tar.gz.

File metadata

  • Download URL: hudu_magic-0.1.26.tar.gz
  • Upload date:
  • Size: 40.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for hudu_magic-0.1.26.tar.gz
Algorithm Hash digest
SHA256 99efaf0dee6e339ccd6c5d924b0af37c8ef1d72330ce3cc8cafb1f90153736c5
MD5 1d1c5cabda47bcc9f8cfe811ec562368
BLAKE2b-256 2081f6749bcf783ee585a972a8e8961457340c54e6a9701cd49aa25804772e7a

See more details on using hashes here.

Provenance

The following attestation bundles were made for hudu_magic-0.1.26.tar.gz:

Publisher: publish-pypi.yml on Hudu-Technologies-Inc/hudu-magic

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hudu_magic-0.1.26-py3-none-any.whl.

File metadata

  • Download URL: hudu_magic-0.1.26-py3-none-any.whl
  • Upload date:
  • Size: 42.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for hudu_magic-0.1.26-py3-none-any.whl
Algorithm Hash digest
SHA256 dbc1761768ce86578a82badc7810092647cd6bf18a0618a3387fae3b7a92eef9
MD5 38c94229a830121c3600e94547bb4412
BLAKE2b-256 db6211bfc0cdb14fad5280c0c13b687dfbfd064f2e1f426d496b5b05357db4cb

See more details on using hashes here.

Provenance

The following attestation bundles were made for hudu_magic-0.1.26-py3-none-any.whl:

Publisher: publish-pypi.yml on Hudu-Technologies-Inc/hudu-magic

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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