Skip to main content

nano implementation of the AT Protocol (Authenticated Transfer Protocol)

Project description

nanoatp

A nano implementation of the AT Protocol (Authenticated Transfer Protocol).

Getting started

First install the package:

pip install nanoatp

Then in your application:

from nanoatp import BskyAgent

agent = BskyAgent("https://bsky.social")

Usage

Session management

Log into a server using these APIs. You'll need an active session for most methods.

from nanoatp import BskyAgent

agent = BskyAgent("https://bsky.social")

agent.login('alice@mail.com', 'hunter2')

# if you don't specify credentials, ATP_IDENTIFIER and ATP_PASSWORD environment variables will be used
# agent.login()

API calls

The agent includes methods for many common operations, including:

# Feeds and content
agent.getPost(repo, rkey, cid)
agent.post(record)
agent.deletePost(postUri)
agent.uploadBlob(data, encoding)
agent.uploadImage(path, alt, encoding)  # wrapper for uploadBlob

# Identity
agent.resolveHandle(handle)

# Session management
agent.login(identifier, password)

For example, to post a record, reply to it, and upload an image:

from nanoatp import BskyAgent

agent = BskyAgent("https://bsky.social")
session = agent.login()

record = {"text": "Hello, world! 0"}
r = agent.post(record)
root = r
parent = r

record = {"text": "Hello, world! 1", "reply": {"root": root, "parent": parent}}
r = agent.post(record)
parent = r

image = agent.uploadImage("favicon-16x16.png", "image/png")
embed = {"$type": "app.bsky.embed.images#main", "images": [image]}
record = {
    "text": "Hello, world! 2",
    "reply": {"root": root, "parent": parent},
    "embed": embed
}
agent.post(record)

Advanced

Advanced API calls

The methods above are convenience wrappers. It covers most but not all available methods.

The AT Protocol identifies methods and records with reverse-DNS names. You can use them on the agent as well:

res1 = agent.createRecord(
    agent.session["did"],  # repo
    "app.bsky.feed.post",  # collection
    {
        "$type": "app.bsky.feed.post",  # record
        "text": "Hello, world!",
        "createdAt": datetime.datetime.now(datetime.timezone.utc).isoformat().replace("+00:00", "Z")
    }
)

Development

export ATP_IDENTIFIER="foo.bsky.social"
export ATP_PASSWORD="password"
poetry install
poetry run pytest -s     # run pytest once
poetry run -- ptw -- -s  # run pytest and watch for changes

License

MIT License. See LICENSE for details.

Author

Susumu Ota

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

nanoatp-0.3.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

nanoatp-0.3.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nanoatp-0.3.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.10.9 Darwin/22.3.0

File hashes

Hashes for nanoatp-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b88def4c4f08ce17a08d36d0e456e78748551bec33931edc3b6e038727ffb7bc
MD5 a8bfd7d923b3f3a419c1907949852192
BLAKE2b-256 c90403d71229f9c38ff3487fa17011d10a565bae115a1b684dd7228c0d6d07dd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nanoatp-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.10.9 Darwin/22.3.0

File hashes

Hashes for nanoatp-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4f89f5b90127fbb9b0a3bfbe79d1740bdfa32e91bdac03f30e853094d34d2607
MD5 92daffd24bc5a80a3c6496003305d201
BLAKE2b-256 4403049fad1bf33a9b6a4487853af76491b7ac8490fbf15984c02dcf4f172f3f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page