Skip to main content

Community-maintained Python client for PrintNode's API

Project description

PrintNode API Client Python Library

[!NOTE] This repository is a community-maintained fork of the PrintNode Python API client. It is not an official PrintNode release unless PrintNode explicitly confirms maintainership or transfer. The maintained project name is printnode_community.

This is a Python library to interact with PrintNode's remote printing API. This client allows you to access the API's functions for quick use in Python scripts.

Requirements

  • Python 3.10+
  • requests
  • future

Installation

After the first maintained release is published, install the package with:

uv add printnode_community

or:

python -m pip install printnode_community

Install from source with uv:

uv sync

For editable development installs, use:

uv pip install -e .

Until the first maintained release is published, prefer installing from a reviewed Git tag or branch rather than relying on an unpublished local build.

Development

Install development dependencies and run tests with:

uv sync
uv run pytest

Build and validate package artifacts with:

uv build
uv run twine check dist/*

Releases

Release publishing is not enabled for general use yet. See RELEASE.md for the release process and TestPyPI/PyPI workflow requirements.

Getting Started

The default constructor for the Library is a Gateway, which is constructed with at minimum of one key-word argument, that being an api-key.

from printnode_community import Gateway
my_account_gateway = Gateway(apikey='my_api_key')

After creating a Gateway, you can access any requests as such:

my_account_id = my_account_gateway.account.id
new_tag = my_account_gateway.ModifyTag("Likes","PrintNode")

Initial Gateway Configuration

You can authenticate in 2 ways other than using an api-key:

Gateway(email='email',password='password')
Gateway(clientkey='ckey')

The three below will authenticate with access to child accounts of a specific user:

Gateway(apikey='api-key',child_email='c_email')
Gateway(apikey='api-key',child_ref='c_creator_ref')
Gateway(apikey='api-key',child_id='c_id')

Gateway Methods

All of these will have the associated API doc next to them. Any of the argument types will be exactly the same as the attributes used in a normal request. Any "Objects" under type are represented as a dict, which will have the same representation as the JSON objects.

Computers Library

This handles anything that is associated with a computer, such as Printers, PrintJobs, States (of PrintJobs) and Scales.

Account lookup

https://www.printnode.com/docs/api/curl/#whoami

account(self)

Returns an Account object of the currently authenticated account.

from printnode_community import Gateway

gateway=Gateway(url='https://api.printnode.com',apikey='secretAPIKey')
print(gateway.account.firstname)

'''
Results:
Mr
'''

Computer lookup

https://www.printnode.com/docs/api/curl/#computers

computers(self, computer)

Given a set of computers, returns these computers. Given only one id, returns that computer.

from printnode_community import Gateway

gateway=Gateway(url='https://api.printnode.com',apikey='secretAPIKey')
print(gateway.computers(computer=10027).name)

'''
Results:
5.2015-07-10 15:04:40.253763.TEST-COMPUTER
'''

Printer lookup

https://www.printnode.com/docs/api/curl/#printers

printers(self, computer=None, printer=None)

There are four ways this can be run:

  • printer & computer argument both None: Gives all printers attached to the account.
  • printer str/int, computer None: Gives a printer found from either an id or the name of a printer, taken from all possible printers.
  • printer None, computer int: Gives all printers attached to the computer given by an id.
  • printer str/int, computer int: Gives a printer found from either an id or the name of a printer, taken only from printers attached to the computer specified by the computer's id.
from printnode_community import Gateway

gateway=Gateway(url='https://api.printnode.com',apikey='secretAPIKey')
print(gateway.printers(printer=50120).name)
for printer in gateway.printers(computer=10027):
    print(printer.name)

'''
Results:
10027.3.TEST-PRINTER
10027.1.TEST-PRINTER
10027.2.TEST-PRINTER
10027.3.TEST-PRINTER
10027.4.TEST-PRINTER
10027.5.TEST-PRINTER
'''

PrintJob lookup

https://www.printnode.com/docs/api/curl/#printjob-viewing

printjobs(self, computer=None, printer=None, printjob=None

There are five ways this can be run:

  • No arguments : Returns all printjobs associated with the account.
  • computer int : Returns all printjobs relative to printers associated with the computer specified by the argument computer.
  • printer int : Returns all printjobs relative to the printer specificed by the argument printer.
  • computer int, printer int : Returns all printjobs relative to the printer specified by the argument printer from printers with access to computer.
  • printjob int : Returns specific printjob.
from printnode_community import Gateway

gateway=Gateway(url='https://api.printnode.com',apikey='secretAPIKey')
printjob_id = gateway.printjobs(computer=10027)[0].id
print(gateway.printjobs(printer=50120)[0].id)
print(gateway.printjobs(printjob=printjob_id))

'''
Results:
251137
PrintJob(id=251127, printer=Printer(id=50118, computer=Computer(id=10027, name='5.2015-07-10 15:04:40.253763.TEST-COMPUTER', inet=None, inet6=None, hostname=None, version=None, create_timestamp='2015-07-10T15:04:40.253Z', state='created'), name='10027.1.TEST-PRINTER', description='description', capabilities={'capability_1': 'one', 'capability_2': 'two'}, default=True, create_timestamp='2015-07-10T15:04:40.253Z', state=None), title='50118.1.TEST-PRINTJOB', content_type='pdf_uri', source='API test endpoint', expire_at=None, create_timestamp='2015-07-10T15:04:40.253Z', state='new')
'''

PrintJob creation

https://www.printnode.com/docs/api/curl/#printjob-creating

PrintJob(self, computer=None, printer=None, job_type='pdf', title='PrintJob',options=None,authentication=None,uri=None,base64=None,binary=None)

Only one of uri, base64 and binary can be chosen.

from printnode_community import Gateway

gateway=Gateway(url='https://api.printnode.com',apikey='secretAPIKey')
print(gateway.PrintJob(printer=50120,options={"copies":2},uri="a.pdf"))

'''
Results:
PrintJob(id=251153, printer=Printer(id=50120, computer=Computer(id=10027, name='5.2015-07-10 15:04:40.253763.TEST-COMPUTER', inet=None, inet6=None, hostname=None, version=None, create_timestamp='2015-07-10T15:04:40.253Z', state='created'), name='10027.3.TEST-PRINTER', description='description', capabilities={'capability_1': 'one', 'capability_2': 'two'}, default=False, create_timestamp='2015-07-10T15:04:40.253Z', state=None), title='PrintJob', content_type='pdf_uri', source='PythonApiClient', expire_at=None, create_timestamp='2015-07-10T15:05:27.087Z', state='new')
'''

State lookup

https://www.printnode.com/docs/api/curl/#printjob-states

states(self, printjob_set)

Given a set of printjobs as a string (check https://www.printnode.com/docs/api/curl/#parameters for examples), returns a list of object type State. As each PrintJob can have many states, states() is a list of PrintJobs that each have a list of States.

from printnode_community import Gateway

gateway=Gateway(url='https://api.printnode.com',apikey='secretAPIKey')
printjob_id = gateway.printjobs(computer=10027)[0].id
print(gateway.states(printjob_id)[0][0].state)

'''
Results:
new
'''

Accounts Library

This handles anything to do with accounts, such as Account creation, deletion and modificaiton, api-key handling, tag handling and Client handling.

Tag lookup

https://www.printnode.com/docs/api/curl/#account-tagging

tag(self, tagname)

Given a tagname, returns the value of that tag.

from printnode_community import Gateway

gateway=Gateway(url='https://api.printnode.com',apikey='secretAPIKey')
print(gateway.tag("Likes"))

'''
Results:
Everything!
'''

Tag modification

ModifyTag(self, tagname, tagvalue)

Given a tagname and tagvalue, either creates a tag with specifed value if tagname doesn't exist, otherwise changes the value.

from printnode_community import Gateway

gateway=Gateway(url='https://api.printnode.com',apikey='secretAPIKey')
gateway.ModifyTag("Likes","PrintNode")
print(gateway.tag("Likes"))

'''
Results:
PrintNode
'''

Tag deletion

DeleteTag(self, tagname)

Given a tagname, deletes that tag. Returns True on successful deletion.

from printnode_community import Gateway

gateway=Gateway(url='https://api.printnode.com',apikey='secretAPIKey')
gateway.ModifyTag("Likes","PrintNode")
gateway.DeleteTag("Likes")
print(gateway.account.tags)

'''
Results:
[]
'''

Account creation

https://www.printnode.com/docs/api/curl/#account-creation

CreateAccount(self, firstname, lastname, email, password, creator_ref=None, api_keys=None, tags=None)

Creates an account with the specified values. The last three are optional.

from printnode_community import Gateway

gateway=Gateway(url='https://api.printnode.com',apikey='secretAPIKey')
new_account = gateway.CreateAccount(
    firstname="A",
    lastname="Person",
    password="password",
    email="aperson@emailprovider.com",
    tags={"Likes":"Something"}
    )
new_account_gateway = Gateway(url='https://api.printnode.com',apikey='secretAPIKey',child_id=new_account["Account"]["id"])
print(new_account_gateway.account.firstname)
new_account_gateway.DeleteAccount()

'''
Results:
A
'''

Account deletion

https://www.printnode.com/docs/api/curl/#account-deletion

DeleteAccount(self)

Deletes the child account that is currently authenticated. Accounts can only be deleted if authenticated by a parent account's api-key and a reference to the child account being deleted (e.g the child account's id)

from printnode_community import Gateway

gateway=Gateway(url='https://api.printnode.com',apikey='secretAPIKey')
new_account = gateway.CreateAccount(
    firstname="A",
    lastname="Person",
    password="password",
    email="aperson@emailprovider.com",
    tags={"Likes":"Something"}
    )
new_account_gateway = Gateway(url='https://api.printnode.com',apikey='secretAPIKey',child_id=new_account["Account"]["id"])
new_account_gateway.DeleteAccount()
print(new_account["Account"]["id"] in gateway.account.child_accounts)

'''
Results:
False
'''

Account modification

https://www.printnode.com/docs/api/curl/#account-modification

ModifyAccount(self, firstname=None, lastname=None, password=None, email=None, creator_ref=None)

Given one or more arguments, changes the account details specified by the arguments.

from printnode_community import Gateway

gateway=Gateway(url='https://api.printnode.com',apikey='secretAPIKey')
new_account = gateway.CreateAccount(
    firstname="A",
    lastname="Person",
    password="password",
    email="aperson@emailprovider.com",
    tags={"Likes":"Something"}
    )
new_account_gateway = Gateway(url='https://api.printnode.com',apikey='secretAPIKey',child_id=new_account["Account"]["id"])
new_account_gateway.ModifyAccount(firstname="B")
print(new_account_gateway.account.firstname)
new_account_gateway.DeleteAccount()

'''
Results:
B
'''

Api-key lookup

https://www.printnode.com/docs/api/curl/#account-apikeys

apikey(self, api_key)

Returns value of api-key specified by the argument.

from printnode_community import Gateway

gateway=Gateway(url='https://api.printnode.com',apikey='secretAPIKey')
new_account = gateway.CreateAccount(
    firstname="A",
    lastname="Person",
    password="password",
    email="aperson@emailprovider.com",
    tags={"Likes":"Something"},
    api_keys=["Production"]
    )
new_account_gateway = Gateway(url='https://api.printnode.com',apikey='secretAPIKey',child_id=new_account["Account"]["id"])
print(new_account_gateway.api_key("Production"))
new_account_gateway.DeleteAccount()

'''
Results:
5a272ed7406d351be86f25be388810dc83b8f52d
'''

API Key Creation

CreateApikey(self, api_key)

Creates an api-key with the api-key's reference given by the argument.

from printnode_community import Gateway

gateway = Gateway(url='https://api.printnode.com',apikey='secretAPIKey')
new_account = gateway.CreateAccount(
    firstname="A",
    lastname="Person",
    password="password",
    email="aperson@emailprovider.com",
    tags={"Likes":"Something"},
    api_keys=["Production"]
    )
new_account_gateway = Gateway(url='https://api.printnode.com',apikey='secretAPIKey',child_id=new_account["Account"]["id"])
new_account_gateway.CreateApiKey("Development")
print(new_account_gateway.account.api_keys)
new_account_gateway.DeleteAccount()

'''
Results:
{'Development': '123SecretAPIKey', 'Production': '456SecretAPIKey'}
'''

API Key Deletion

DeleteApikey(self, api_key)

Deletes api-key specified by the argument.

from printnode_community import Gateway

gateway=Gateway(url='https://api.printnode.com',apikey='secretAPIKey')
new_account = gateway.CreateAccount(
    firstname="A",
    lastname="Person",
    password="password",
    email="aperson@emailprovider.com",
    tags={"Likes":"Something"},
    api_keys=["Production"]
    )
new_account_gateway = Gateway(url='https://api.printnode.com',apikey='secretAPIKey',child_id=new_account["Account"]["id"])
new_account_gateway.DeleteApiKey("Production")
print(new_account_gateway.account.api_keys)
new_account_gateway.DeleteAccount()

'''
Results:
[]
'''

Client Key creation

https://www.printnode.com/docs/api/curl/#account-delegated-auth

clientkey(self, uuid, edition, version)

Generates a clientkey for the account.

from printnode_community import Gateway

gateway=Gateway(url='https://api.printnode.com',apikey='secretAPIKey')
new_account = gateway.CreateAccount(
    firstname="A",
    lastname="Person",
    password="password",
    email="aperson@emailprovider.com",
    tags={"Likes":"Something"},
    api_keys=["Production"]
    )
new_account_gateway = Gateway(url='https://api.printnode.com',apikey='secretAPIKey',child_id=new_account["Account"]["id"])
new_clientkey = new_account_gateway.clientkey(
    uuid="0a756864-602e-428f-a90b-842dee47f57e",
    edition="printnode",
    version="4.7.2")
print(new_clientkey)
new_account_gateway.DeleteAccount()

'''
Results:
ck-nwa2SSvSGl1YR5zrHDVVgfdpJ8JLfVCvwaCWj8dQXmZW
'''

Download client lookup

https://www.printnode.com/docs/api/curl/#account-download-management

clients(self, client_ids = None, os = None)

This has three different outcomes:

  • os and client_ids both None: Returns all clients available for the current account.
  • os str and client_ids None: Returns the most recent version for given OS ("windows" or "osx" only)
  • os None and client_ids str: Given a set of ids (e.g "11-15"), return all clients in that set.

Having both set will default to showing the most recent version for the os argument.

from printnode_community import Gateway

gateway=Gateway(url='https://api.printnode.com',apikey='secretAPIKey')
for client in gateway.clients(client_ids="11-12"):
    print(client.id)
print(gateway.clients(os="windows").os)

'''
Results:
12
11
windows
'''

Download client controlling

ModifyClientDownloads(self, client_id, enabled)

Given a set of ids and either True or False, sets whether the clients are enabled or not. Returns a list of modified clients.

from printnode_community import Gateway

gateway=Gateway(url='https://api.printnode.com',apikey='secretAPIKey')
gateway.ModifyClientDownloads(11,False)
print(gateway.clients(client_ids=11)[0].enabled)

'''
Results:
False
'''

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

printnode_community-0.3.0.tar.gz (60.1 kB view details)

Uploaded Source

Built Distribution

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

printnode_community-0.3.0-py3-none-any.whl (15.7 kB view details)

Uploaded Python 3

File details

Details for the file printnode_community-0.3.0.tar.gz.

File metadata

  • Download URL: printnode_community-0.3.0.tar.gz
  • Upload date:
  • Size: 60.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for printnode_community-0.3.0.tar.gz
Algorithm Hash digest
SHA256 c9ded7f163f0f68a6a13bbb0dfdba20f01e8c0a6ddd824f5bccbeb0de2e0243a
MD5 2b1b4151ed98ad311d5e23db978375a4
BLAKE2b-256 0f43d6440f2af512815f617e81d6c1d42bf62d6608d5fd3b0151fa8c04bde941

See more details on using hashes here.

Provenance

The following attestation bundles were made for printnode_community-0.3.0.tar.gz:

Publisher: publish.yml on cbusillo/printnode_community

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

File details

Details for the file printnode_community-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for printnode_community-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f2b7c952d4722920785e2a024332e07023ee1e8faa1aa9382a887db68a94cdcc
MD5 667109b258d6af4001cb4e52f986ead2
BLAKE2b-256 6c016334b95a6761ef96fb0172fcfc7fd043c5ce5fa4e761a606dcdc8ed81bb2

See more details on using hashes here.

Provenance

The following attestation bundles were made for printnode_community-0.3.0-py3-none-any.whl:

Publisher: publish.yml on cbusillo/printnode_community

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