Skip to main content

Pico ACME: tiny ACMEv2 client

Project description

pico acme

The tiniest python package to get ACMEv2 certs from Let's Encrypt.

Supports only single domains and DNS challenge. Currently implements AWS Route 53 but you can trivially implement your own provider.

Licensed under Apache 2.0 as this reuses some code from certbot.

quick start

Install from PyPI:

pip install pico-acme

(Note that you need to install boto3 separately to use route53.)

new.py:

ROUTE53_HOSTED_ZONE_ID = "..."
ACCOUNT_EMAIL = "domains@example.com"
DOMAIN = "example.com"

# create account, get cert, and save details
import pico_acme
from pico_acme import route53

# register an acme account
acme_client = pico_acme.register_account(ACCOUNT_EMAIL, agree_tos=True)

# create a private key and certificate signing request
key_pem = pico_acme.make_key()
csr_pem = pico_acme.make_csr(key_pem, [DOMAIN])

# get functions for upserting and cleaning up DNS records in AWS Route 53
upsert, clean = route53.route53_upsert_cleanup(ROUTE53_HOSTED_ZONE_ID)

# perform DNS-01 challenge to get the full chain as PEM
fullchain_pem = pico_acme.perform_dns01(acme_client, DOMAIN, csr_pem, upsert, clean)

# save account for later
with open("pico_acme_account.json", "w") as f:
    f.write(pico_acme.serialize_account(acme_client))

# save private key for later
with open("key.pem", "wb") as f:
    f.write(key_pem)

# save the cert for later
with open("fullchain.pem", "w") as f:
    f.write(fullchain_pem)

renew.py:

ROUTE53_HOSTED_ZONE_ID = "..."
DOMAIN = "example.com"

# later, load account, private key, and renew cert
import pico_acme
from pico_acme import route53

# load account
with open("pico_acme_account.json") as f:
    acme_client = pico_acme.deserialize_account(f.read())

# load private key
with open("key.pem", "rb") as f:
    key_pem = f.read()

# make a new certificate signing request
csr_pem = pico_acme.make_csr(key_pem, [DOMAIN])

# get functions for upserting and cleaning up DNS records in AWS Route 53
upsert, clean = route53.route53_upsert_cleanup(ROUTE53_HOSTED_ZONE_ID)

# perform DNS-01 challenge to get the full chain as PEM
fullchain_pem = pico_acme.perform_dns01(acme_client, DOMAIN, csr_pem, upsert, clean)

# save the cert for later
with open("fullchain.pem", "w") as f:
    f.write(fullchain_pem)

checking if you need to renew

import pico_acme

with open("fullchain.pem") as f:
    fullchain_pem = f.read()

if pico_acme.should_renew(fullchain_pem):
    print("due for renewal")

architecture & features

The perform_dns01 takes two callables, upsert(record, value) which should set the value value (the verification string) in record record (e.g. _acme-challenge.example.com), and clean(record, value) which should clean these up. See the route53.py implementation for details.

acknowledgements

This is based very heavily on certbot, with portions copied directly.

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

pico_acme-0.1.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

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

pico_acme-0.1.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file pico_acme-0.1.0.tar.gz.

File metadata

  • Download URL: pico_acme-0.1.0.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pico_acme-0.1.0.tar.gz
Algorithm Hash digest
SHA256 60c30abc0cc1717f816dd2c306453e75ca132082021eeb9e446bb9ff26eb3da1
MD5 06e038b18c612d3abeb5db47130bd1c5
BLAKE2b-256 2e09dee205cb6374bb5698dde000bed7d0f2e7de8ae14462f303e50d1f45cc3a

See more details on using hashes here.

File details

Details for the file pico_acme-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pico_acme-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pico_acme-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dc4ba002da4b9680b41c482119aee02f33f234de633be570618a22813d67df9a
MD5 46dc2d18108d9fa1a4807eb555876020
BLAKE2b-256 e05def81ec1357d6c202158a45dc046ba924eadbb3c05c7bbf0a8b553ac1224e

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