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

# 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.2.0.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

nanoatp-0.2.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for nanoatp-0.2.0.tar.gz
Algorithm Hash digest
SHA256 bd1e03ff247227d9fa41fd51bece7d733df45c452b640d9d401154d8e6769848
MD5 884917ddc05c6a34a8c98dfa1dc21c77
BLAKE2b-256 e4b6f3b21c69958cf528360c65b13420b424f24216fcb876fafb0591bc964438

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for nanoatp-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a252194120c220d115ca38beeba8cff2669d0cdf06ea3a346b883a06744bba88
MD5 06d5bedce2a293763de27b55a6e19410
BLAKE2b-256 d5069f1e51ae8eef3cce4ed1017af929af557207fecb1ba415927c7afd5446e3

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