Metadata-Version: 2.4
Name: fulcrumpro
Version: 0.25.1
Summary: A lightweight Python SDK for the Fulcrum Pro API, built with `httpx2`.
Requires-Python: >=3.14
Description-Content-Type: text/markdown
Requires-Dist: httpx2>=2.4.0
Requires-Dist: tenacity>=9.1.4

# FulcrumPro

A lightweight Python SDK for the [Fulcrum Pro](https://fulcrumpro.com) API, built on [`httpx`](https://www.python-httpx.org/).

## Installation

```bash
pip install fulcrumpro
```

Or with `uv`:

```bash
uv add fulcrumpro
```

## Requirements

- Python 3.14+

## Quick Start

```python
from fulcrumpro import FulcrumPro

client = FulcrumPro(api_token="your-api-token")

job = client.jobs.get("6a0e5cad7c2e97225f8def9c")
print(job["name"])
```

Use as a context manager to ensure the underlying HTTP connection is closed:

```python
with FulcrumPro(api_token="your-api-token") as client:
    job = client.jobs.get("6a0e5cad7c2e97225f8def9c")
```

## Authentication

All requests are authenticated with a Bearer token. Pass your API token when constructing the client:

```python
client = FulcrumPro(api_token="your-api-token")
```

## Resources

### Items

An item's **master routing** — the operations it is built through, as opposed to
the operations recorded against a particular job:

```python
for operation in client.items.routing_operations(item_id).stream():
    print(operation["name"], operation["order"])
```

This is item master data, so it answers for items that have never been built.
`jobs.get_operations(job_id)` cannot: it only describes items something has
already been made from.

**An empty list has two meanings, and this endpoint cannot tell them apart.**
Both answer 200 with `[]`:

```python
client.items.routing_operations(make_item_id).list()  # [] — routed through nothing
client.items.routing_operations(bought_item_id).list()  # [] — never had a routing
```

The first is 17% of `make` items, measured against production. The second is
every `buy` and `customerSupplied` part. **So filter by item origin before
asking** — a sweep that doesn't will report every purchased part as un-routed,
with a 200 and nothing to suggest the question was meaningless for it.

`GET /items/{id}/routing` does distinguish them (200 against 400) and is
deliberately not wrapped here: the item's own `itemOrigin` already answers it
without spending a request.

**Prefer `stream` to `list`.** `take` defaults to **50** server-side, so a bare
`list()` on an item with more operations than that returns exactly 50, with
nothing to indicate it was truncated. The same applies to `input_items`, which
is the item's BOM on the same routing:

```python
inputs = list(client.items.input_items(item_id).stream())
```

### Tags, and why item categories live here

Several of Fulcrum's named lists are the same underlying object — a **tag** —
distinguished only by the `types` array on it. Item categories are one of them,
along with accounting codes, item shapes, materials, grades, gauges, shipping
containers and item classes. A tag can belong to more than one list.

`client.item_categories` reads categories through the `/item-categories` routes,
but those are read-only: there is no `POST /item-categories`. **Creating a
category means creating a tag**:

```python
category = client.tags.create(
    {
        "name": "Subassembly",
        "style": "secondary",
        "types": ["itemCategory"],
    }
)

client.items.update(
    item_id, [{"op": "replace", "path": "/categoryId", "value": category["id"]}]
)
```

`name`, `style` and `types` are all required, and `types` needs at least one
entry. **`create` returns the id alone** — `{"id": ...}`, not the created tag —
so `get` it if you need the stored record. The new tag is immediately readable
through `client.item_categories`.

**Tag names must be unique, and the check ignores case.** Creating `Aluminum`
while `ALUMINUM` exists is refused:

```
FulcrumProError: FulcrumPro API error 400:
{'ErrorMessage': 'Validation failed: \n -- Name: Tag name must be unique.'}
```

The same check runs on `update`, so a rename cannot introduce a collision
either, and a refused call leaves the tag untouched.

An existing instance may still *hold* case-variant pairs — production has both
`Relay` and `RELAY` — but those predate the constraint or arrived by import, and
cannot be created through the API. Don't read such a pair as evidence that a
create will go through.

Check case-insensitively before creating. Where the collision is only a casing
difference you want corrected, rename the existing tag instead of creating a
second one:

```python
client.tags.update(tag_id, [{"op": "replace", "path": "/name", "value": "Aluminum"}])
```

That preserves the id and the `types` array, so every item already pointing at
the tag follows the rename.

It also coerces a null `description` to `""`, **and that cannot be undone** —
patching `/description` back to `None` leaves it `""`. So a rename permanently
changes a second field.

There is no delete route, so a tag created by mistake stays.

### Jobs

```python
# Get a job by ID
job = client.jobs.get("6a0e5cad7c2e97225f8def9c")
```

### Attachments

Upload a file to a Fulcrum record. Every attachment needs an owner — the record
it hangs off — and `file` accepts a path, raw `bytes`, or an open binary file
object, with a path opened and closed for you:

```python
created = client.attachments.upload(
    "drawing.pdf",
    owner_type="job",
    owner_id="6a0e5cad7c2e97225f8def9c",
    description="Revision C drawing",
    metadata={"source": "sdk"},
)
```

Download one by ID. Omit `dest` to get the content back as `bytes`, or pass a
path to stream it straight to disk without buffering it in memory:

```python
content = client.attachments.download(created["id"])
path = client.attachments.download(created["id"], dest="drawing.pdf")
```

Find attachments on a record, and download them all as a single ZIP:

```python
owner = {"type": "job", "id": "6a0e5cad7c2e97225f8def9c"}

for attachment in client.attachments.stream(data={"owner": owner}):
    print(attachment["name"], attachment["size"])

client.attachments.download_many(data={"owner": owner}, dest="attachments.zip")
```

Queries must always be narrowed by `owner`, `owners` or `attachmentIds` — the
API will not enumerate every attachment in a tenant, and `formats` on its own
doesn't count. An unfiltered call raises `ValueError` rather than making a
request. To sweep broadly, iterate the owning records:

```python
for job in client.jobs.stream():
    owner = {"type": "job", "id": job["id"]}
    for attachment in client.attachments.stream(data={"owner": owner}):
        ...
```

`owners` takes up to 500 at a time, so batching is usually faster than one
request per record.

#### Known gap: attachments on a job operation

Files attached to a job operation — including note attachments added through the
Fulcrum UI — are stored with an owner type (`Job_ItemToMake_Operation`) that the
public API's owner enum doesn't include. It can't be sent as a filter (`list`
returns 400) and can't be read back (`get` returns 500). The failure happens
while serializing the record, so any query that would return one fails — these
attachments can't be discovered through the public API at all.

Downloads are unaffected, because they return bytes and never build an owner
object. If you obtain an ID another way, the file itself is retrievable:

```python
client.attachments.download("6aa82ae1f826405557c34006", dest="photo.png")
```

Certification attachments and remotely hosted files have their own methods:

```python
client.attachments.upload_certification(
    "cert.pdf", owner_type="item", owner_id="...", lot_id="..."
)
client.attachments.create_remote(
    owner, file_name="spec.pdf", access_url="https://example.com/spec.pdf"
)

client.attachments.delete(created["id"])
```

## Error Handling

All non-2xx responses raise a `FulcrumProError`:

```python
from fulcrumpro import FulcrumPro, FulcrumProError

client = FulcrumPro(api_token="your-api-token")

try:
    job = client.jobs.get("nonexistent-id")
except FulcrumProError as e:
    print(e.status_code)  # e.g. 404
    print(str(e))  # "FulcrumPro API error 404: not found"
```

## Version History

See [CHANGELOG.md](CHANGELOG.md).

## Docs
Full API documentation can be found on [GitHub Pages](https://cautious-adventure-v3ezn65.pages.github.io/fulcrumpro.html)
