Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement atproto identity (DID and Handle resolvers) and DID Document #219

Merged
merged 15 commits into from
Dec 23, 2023
Merged
4 changes: 4 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[run]
omit =
# ignore all test cases in tests/
tests/*
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ jobs:
files.pythonhosted.org
install.python-poetry.org
pypi.org
*.atproto.blue
*.marshal.dev
plc.directory

- name: Checkout repository.
uses: actions/checkout@v4
Expand Down
5 changes: 1 addition & 4 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@

**21.12.2023**

# ❗Breaking changes
**❗Breaking changes:** SDK was split into many packages. This affects imports in your codebase. [Read more](https://atproto.blue/en/latest/readme.content.html#sdk-structure)

SDK was split into many packages. This affects imports in your codebase. [Read more](https://atproto.blue/en/latest/readme.content.html#sdk-structure)

## What's Changed
* New SDK structure by @MarshalX in https://github.com/MarshalX/atproto/pull/214 and https://github.com/MarshalX/atproto/pull/216
* Fix decoding of CAR root by @MarshalX in https://github.com/MarshalX/atproto/pull/213
* Fix parsing of BlobRef in CBOR by @MarshalX in https://github.com/MarshalX/atproto/pull/215
Expand Down
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ if __name__ == '__main__':

🍿 [Example project with custom feed generator](https://github.com/MarshalX/bluesky-feed-generator)

🔥 [Firehose data streaming is available!](https://atproto.blue/en/latest/firehose.html)
🔥 [Firehose data streaming is available](https://atproto.blue/en/latest/firehose.html)

🌐 [Identity resolvers for DID and Handle](https://atproto.blue/en/latest/atproto_identity/identity.html)

### Introduction

Expand Down Expand Up @@ -138,13 +140,17 @@ Useful links to continue:
### SDK structure

The SDK is built upon the following components:
- `atproto` — the package that contains import shortcuts to other packages.
- `atproto_cli` — the package that contains the CLI tool to generate code.
- `atproto_client` — the package that contains the XRPC Client, data models, and utils like rich text helper.
- `atproto_codegen` — the package that contains the code generator of models, clients, and namespaces.
- `atproto_core` — the package that contains the core of the SDK. Base class of exceptions, tools to work with NSID, AT URI Schemes, CID, and CAR files.
- `atproto_firehose` — the package that contains the Firehose (data streaming) client and models.
- `atproto_lexicon` — the package that contains the lexicon parser.

| Package | Description |
|--------------------|---------------------------------------------------------------------------------------------------------------------------------------|
| `atproto` | The package that contains import shortcuts to other packages. |
| `atproto_cli` | The package that contains the CLI tool to generate code. |
| `atproto_client` | The package that contains the XRPC Client, data models, and utils like rich text helper. |
| `atproto_codegen` | The package that contains the code generator of models, clients, and namespaces. |
| `atproto_core` | The package that contains the core of the SDK. Base class of exceptions, tools to work with NSID, AT URI Schemes, CID, and CAR files. |
| `atproto_firehose` | The package that contains the Firehose (data streaming) client and models. |
| `atproto_identity` | The package that contains the identity resolvers for DID and Handle. |
| `atproto_lexicon` | The package that contains the lexicon parser. |

I highly recommend you to use the `atproto` package to import everything that you need.
It contains shortcuts to all other packages.
Expand Down
7 changes: 7 additions & 0 deletions docs/source/atproto/atproto_core.did_doc.did_doc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
atproto\_core.did\_doc.did\_doc
===============================

.. automodule:: atproto_core.did_doc.did_doc
:members:
:undoc-members:
:show-inheritance:
15 changes: 15 additions & 0 deletions docs/source/atproto/atproto_core.did_doc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
atproto\_core.did\_doc
======================

.. automodule:: atproto_core.did_doc
:members:
:undoc-members:
:show-inheritance:

Submodules
----------

.. toctree::
:maxdepth: 4

atproto_core.did_doc.did_doc
1 change: 1 addition & 0 deletions docs/source/atproto/atproto_core.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Subpackages
atproto_core.car
atproto_core.cbor
atproto_core.cid
atproto_core.did_doc
atproto_core.nsid
atproto_core.uri

Expand Down
7 changes: 7 additions & 0 deletions docs/source/atproto/atproto_identity.cache.base_cache.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
atproto\_identity.cache.base\_cache
===================================

.. automodule:: atproto_identity.cache.base_cache
:members:
:undoc-members:
:show-inheritance:
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
atproto\_identity.cache.in\_memory\_cache
=========================================

.. automodule:: atproto_identity.cache.in_memory_cache
:members:
:undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docs/source/atproto/atproto_identity.cache.models.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
atproto\_identity.cache.models
==============================

.. automodule:: atproto_identity.cache.models
:members:
:undoc-members:
:show-inheritance:
17 changes: 17 additions & 0 deletions docs/source/atproto/atproto_identity.cache.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
atproto\_identity.cache
=======================

.. automodule:: atproto_identity.cache
:members:
:undoc-members:
:show-inheritance:

Submodules
----------

.. toctree::
:maxdepth: 4

atproto_identity.cache.base_cache
atproto_identity.cache.in_memory_cache
atproto_identity.cache.models
7 changes: 7 additions & 0 deletions docs/source/atproto/atproto_identity.did.atproto_data.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
atproto\_identity.did.atproto\_data
===================================

.. automodule:: atproto_identity.did.atproto_data
:members:
:undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docs/source/atproto/atproto_identity.did.models.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
atproto\_identity.did.models
============================

.. automodule:: atproto_identity.did.models
:members:
:undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docs/source/atproto/atproto_identity.did.resolver.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
atproto\_identity.did.resolver
==============================

.. automodule:: atproto_identity.did.resolver
:members:
:undoc-members:
:show-inheritance:
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
atproto\_identity.did.resolvers.base\_resolver
==============================================

.. automodule:: atproto_identity.did.resolvers.base_resolver
:members:
:undoc-members:
:show-inheritance:
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
atproto\_identity.did.resolvers.plc\_resolver
=============================================

.. automodule:: atproto_identity.did.resolvers.plc_resolver
:members:
:undoc-members:
:show-inheritance:
17 changes: 17 additions & 0 deletions docs/source/atproto/atproto_identity.did.resolvers.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
atproto\_identity.did.resolvers
===============================

.. automodule:: atproto_identity.did.resolvers
:members:
:undoc-members:
:show-inheritance:

Submodules
----------

.. toctree::
:maxdepth: 4

atproto_identity.did.resolvers.base_resolver
atproto_identity.did.resolvers.plc_resolver
atproto_identity.did.resolvers.web_resolver
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
atproto\_identity.did.resolvers.web\_resolver
=============================================

.. automodule:: atproto_identity.did.resolvers.web_resolver
:members:
:undoc-members:
:show-inheritance:
25 changes: 25 additions & 0 deletions docs/source/atproto/atproto_identity.did.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
atproto\_identity.did
=====================

.. automodule:: atproto_identity.did
:members:
:undoc-members:
:show-inheritance:

Subpackages
-----------

.. toctree::
:maxdepth: 4

atproto_identity.did.resolvers

Submodules
----------

.. toctree::
:maxdepth: 4

atproto_identity.did.atproto_data
atproto_identity.did.models
atproto_identity.did.resolver
7 changes: 7 additions & 0 deletions docs/source/atproto/atproto_identity.exceptions.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
atproto\_identity.exceptions
============================

.. automodule:: atproto_identity.exceptions
:members:
:undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docs/source/atproto/atproto_identity.handle.resolver.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
atproto\_identity.handle.resolver
=================================

.. automodule:: atproto_identity.handle.resolver
:members:
:undoc-members:
:show-inheritance:
15 changes: 15 additions & 0 deletions docs/source/atproto/atproto_identity.handle.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
atproto\_identity.handle
========================

.. automodule:: atproto_identity.handle
:members:
:undoc-members:
:show-inheritance:

Submodules
----------

.. toctree::
:maxdepth: 4

atproto_identity.handle.resolver
7 changes: 7 additions & 0 deletions docs/source/atproto/atproto_identity.resolver.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
atproto\_identity.resolver
==========================

.. automodule:: atproto_identity.resolver
:members:
:undoc-members:
:show-inheritance:
26 changes: 26 additions & 0 deletions docs/source/atproto/atproto_identity.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
atproto\_identity
=================

.. automodule:: atproto_identity
:members:
:undoc-members:
:show-inheritance:

Subpackages
-----------

.. toctree::
:maxdepth: 4

atproto_identity.cache
atproto_identity.did
atproto_identity.handle

Submodules
----------

.. toctree::
:maxdepth: 4

atproto_identity.exceptions
atproto_identity.resolver
1 change: 1 addition & 0 deletions docs/source/atproto/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ packages
atproto_codegen
atproto_core
atproto_firehose
atproto_identity
atproto_lexicon
atproto_server
38 changes: 38 additions & 0 deletions docs/source/atproto_identity/cache.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Cache
=====

Cache could be used to store previously resolved DID Documents. SDK provides ``DidInMemoryCache`` and ``DidBaseCache`` classes.

``DidInMemoryCache`` is a simple implementation of ``DidBaseCache`` that stores data in memory. Feel free to use it as real cache or as a reference implementation.

``DidBaseCache`` is an abstract class that could be used to implement custom cache. Please note that there is 2 base classes. One for synchronous and another for asynchronous cache.

Here is an example of how to use ``DidInMemoryCache`` with ``IdResolver``:

.. code-block:: python

from atproto import DidInMemoryCache, IdResolver # for async AsyncDidInMemoryCache and AsyncIdResolver

cache = DidInMemoryCache()
resolver = IdResolver(cache=cache)
did_doc = resolver.did.resolve('did:web:feed.atproto.blue')

# Now did_document is cached and could be retrieved without network request
did_doc = resolver.did.resolve('did:web:feed.atproto.blue')

# Clear cache
cache.clear()

# Now did_document is not cached and will be retrieved with network request
did_doc = resolver.did.resolve('did:web:feed.atproto.blue')


.. automodule:: atproto_identity.cache.in_memory_cache
:members:
:undoc-members:
:show-inheritance:

.. automodule:: atproto_identity.cache.base_cache
:members:
:undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docs/source/atproto_identity/did_resolver.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
DID Resolver
============

.. automodule:: atproto_identity.did.resolver
:members:
:undoc-members:
:inherited-members:
7 changes: 7 additions & 0 deletions docs/source/atproto_identity/handle_resolver.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Handle Resolver
===============

.. automodule:: atproto_identity.handle.resolver
:members:
:undoc-members:
:inherited-members:
7 changes: 7 additions & 0 deletions docs/source/atproto_identity/id_resolver.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ID Resolver
===========

.. automodule:: atproto_identity.resolver
:members:
:undoc-members:
:inherited-members:
Loading
Loading