Code Monkey home page Code Monkey logo

localstack-extensions's Introduction

LocalStack Extensions (Preview)

LocalStack Extensions

With LocalStack 1.0 we have introduced LocalStack Extensions that allow developers to extend and customize LocalStack. Both the feature and the API are currently in preview and may be subject to change.

Using Extensions

Extensions are a LocalStack Pro feature. To use and install extensions, use the CLI to first log in to your account

$ localstack auth login
Please provide your login credentials below
Username: ...
$ localstack extensions --help

Usage: localstack extensions [OPTIONS] COMMAND [ARGS]...

  (Preview) Manage LocalStack extensions.

  LocalStack Extensions allow developers to extend and customize LocalStack.
  The feature and the API are currently in a preview stage and may be subject to change.

  Visit https://docs.localstack.cloud/references/localstack-extensions/
  for more information on LocalStack Extensions.

Options:
  -v, --verbose  Print more output
  -h, --help     Show this message and exit.

Commands:
  dev        Developer tools for developing LocalStack extensions.
  init       Initialize the LocalStack extensions environment.
  install    Install a LocalStack extension.
  list       List installed extension.
  uninstall  Remove a LocalStack extension.

To install an extension, specify the name of the pip dependency that contains the extension. For example, for the official Stripe extension, you can either use the package distributed on pypi:

$ localstack extensions install localstack-extension-httpbin

or you can install the latest version directly from this Git repository

$ localstack extensions install "git+https://github.com/localstack/localstack-extensions/#egg=localstack-extension-httpbin&subdirectory=httpbin"

Official LocalStack Extensions

Here is the current list of extensions developed by the LocalStack team and their support status. You can install the respective extension by calling localstack install <Install name>.

Extension Install name Version Support status
AWS replicator localstack-extension-aws-replicator 0.1.7 Experimental
Diagnosis Viewer localstack-extension-diagnosis-viewer 0.1.0 Stable
Hello World localstack-extension-hello-world 0.1.0 Stable
httpbin localstack-extension-httpbin 0.1.0 Stable
MailHog localstack-extension-mailhog 0.1.0 Stable
Miniflare localstack-extension-miniflare 0.1.0 Experimental
Stripe localstack-extension-stripe 0.1.0 Stable

Developing Extensions

This section provides a brief overview of how to develop your own extensions.

The extensions API

LocalStack exposes a Python API for building extensions that can be found in the core codebase in localstack.extensions.api.

The basic interface to implement is as follows:

class Extension(BaseExtension):
    """
    An extension that is loaded into LocalStack dynamically. The method
    execution order of an extension is as follows:

    - on_extension_load
    - on_platform_start
    - update_gateway_routes
    - update_request_handlers
    - update_response_handlers
    - on_platform_ready
    - on_platform_shutdown
    """

    namespace: str = "localstack.extensions"
    """The namespace of all basic localstack extensions."""

    name: str
    """The unique name of the extension set by the implementing class."""

    def on_extension_load(self):
        """
        Called when LocalStack loads the extension.
        """
        pass

    def on_platform_start(self):
        """
        Called when LocalStack starts the main runtime.
        """
        pass

    def on_platform_shutdown(self):
        """
        Called when LocalStack is shutting down. Can be used to close any resources (threads, processes, sockets, etc.).
        """
        pass

    def update_gateway_routes(self, router: Router[RouteHandler]):
        """
        Called with the Router attached to the LocalStack gateway. Overwrite this to add or update routes.
        :param router: the Router attached in the gateway
        """
        pass

    def update_request_handlers(self, handlers: CompositeHandler):
        """
        Called with the custom request handlers of the LocalStack gateway. Overwrite this to add or update handlers.
        :param handlers: custom request handlers of the gateway
        """
        pass

    def update_response_handlers(self, handlers: CompositeResponseHandler):
        """
        Called with the custom response handlers of the LocalStack gateway. Overwrite this to add or update handlers.
        :param handlers: custom response handlers of the gateway
        """
        pass

    def on_platform_ready(self):
        """
        Called when LocalStack is ready and the Ready marker has been printed.
        """
        pass

A minimal example would look like this:

import logging
from localstack.extensions.api import Extension

LOG = logging.getLogger(__name__)

class ReadyAnnouncerExtension(Extension):
    name = "my_ready_announcer"

    def on_platform_ready(self):
    	LOG.info("my plugin is loaded and localstack is ready to roll!")

Package your Extension

Your extensions needs to be packaged as a Python distribution with a setup.cfg or setup.py config. LocalStack uses the Plux code loading framework to load your code from a Python entry point. You can either use Plux to discover the entrypoints from your code when building and publishing your distribution, or manually define them as in the example below.

A minimal setup.cfg for the extension above could look like this:

[metadata]
name = localstack-extension-ready-announcer
description = LocalStack extension that logs when LocalStack is ready to receive requests
author = Your Name
author_email = [email protected]
url = https://link-to-your-project

[options]
zip_safe = False
packages = find:
install_requires =
    localstack>=1.0.0

[options.entry_points]
localstack.extensions =
    my_ready_announcer = localstack_announcer.extension:ReadyAnnouncerExtension

The entry point group is the Plux namespace locastack.extensions, and the entry point name is the plugin name my_ready_announcer. The object reference points to the plugin class.

Using the extensions CLI

The extensions CLI has a set of developer commands that allow you to create new extensions, and toggle local dev mode for extensions. Extensions that are toggled for developer mode will be mounted into the localstack container so you don't need to re-install them every time you change something.

Usage: localstack extensions dev [OPTIONS] COMMAND [ARGS]...

  Developer tools for developing Localstack extensions

Options:
  --help  Show this message and exit.

Commands:
  disable  Disables an extension on the host for developer mode.
  enable   Enables an extension on the host for developer mode.
  list     List LocalStack extensions for which dev mode is enabled.
  new      Create a new LocalStack extension from the official extension...

Creating a new extensions

First, create a new extensions from a template:

 % localstack extensions dev new
project_name [My LocalStack Extension]: 
project_short_description [All the boilerplate you need to create a LocalStack extension.]: 
project_slug [my-localstack-extension]: 
module_name [my_localstack_extension]: 
full_name [Jane Doe]: 
email [[email protected]]: 
github_username [janedoe]: 
version [0.1.0]: 

This will create a new python project with the following layout:

my-localstack-extension
โ”œโ”€โ”€ Makefile
โ”œโ”€โ”€ my_localstack_extension
โ”‚ย ย  โ”œโ”€โ”€ extension.py
โ”‚ย ย  โ””โ”€โ”€ __init__.py
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ setup.cfg
โ””โ”€โ”€ setup.py

Then run make install in the newly created project to make a distribution package.

Start LocalStack with the extension

To start LocalStack with the extension in dev mode, first enable it by running:

localstack extensions dev enable ./my-localstack-extension

Then, start LocalStack with EXTENSION_DEV_MODE=1

EXTENSION_DEV_MODE=1 LOCALSTACK_API_KEY=... localstack start

In the LocalStack logs you should then see something like:

==================================================
๐Ÿ‘ท LocalStack extension developer mode enabled ๐Ÿ—
- mounting extension /opt/code/extensions/my-localstack-extension
Resuming normal execution, ...
==================================================

Now, when you make changes to your extensions, you just need to restart LocalStack and the changes will be picked up by LocalStack automatically.

localstack-extensions's People

Contributors

alexrashed avatar dominikschubert avatar harshcasper avatar joe4dev avatar lakkeger avatar lukqw avatar pinzon avatar sannya-singal avatar thrau avatar whummer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

localstack-extensions's Issues

Remove usages of deprecated LocalStack code features in AWS replicator

Currently, the AWS Replicator extension is using some parts of the LocalStack codebase which is deprecated and about to be removed:

  • localstack.utils.server.http2_server.run_server which is based on Quart (which has been superseded by the underlying hypercorn quite some time ago).
  • localstack.aws.api.HttpRequest which should be replaced with localstack.http.Request.

These usages are currently blocking the following PRs in localstack/localstack:

It would be best to refactor the AWS Replicator Extension such that it spawns the Auth Proxy a new Gateway (and migrate the logic to a implement a LocalStack handlerchain handler).
/cc @lukqw @whummer @thrau

localstack extensions install fails under Windows

I am unable to download the extension.

localstack extensions install "git+https://github.com/localstack/localstack-extensions/#egg=localstack-extensions-stripe&subdirectory=stripe"

C:\LocalStack>python "C:\Users\marce\AppData\Local\Programs\Python\Python310\Scripts\\localstack" extensions install git+https://github.com/localstack/localstack-extensions/#egg=localstack-extensions-stripe 
Traceback (most recent call last):
  File "C:\Users\marce\AppData\Local\Programs\Python\Python310\lib\site-packages\localstack\utils\container_utils\docker_cmd_client.py", line 659, in _run_async_cmd
    raise subprocess.CalledProcessError(
subprocess.CalledProcessError: Command '['docker', 'start', 'b237ebd94f05a7204601cca7a314c7db9ca3954989c73610271d891d803a0259']' returned non-zero exit status 1.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\marce\AppData\Local\Programs\Python\Python310\Scripts\localstack", line 23, in <module>
    main()
  File "C:\Users\marce\AppData\Local\Programs\Python\Python310\Scripts\localstack", line 19, in main
    main.main()
  File "C:\Users\marce\AppData\Local\Programs\Python\Python310\lib\site-packages\localstack\cli\main.py", line 17, in main
    cli()
  File "C:\Users\marce\AppData\Local\Programs\Python\Python310\lib\site-packages\localstack\cli\plugin.py", line 15, in __call__
    self.group(*args, **kwargs)
  File "C:\Users\marce\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "C:\Users\marce\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py", line 782, in main
    rv = self.invoke(ctx)
  File "C:\Users\marce\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "C:\Users\marce\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "C:\Users\marce\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "C:\Users\marce\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "C:\Users\marce\AppData\Local\Programs\Python\Python310\lib\site-packages\localstack\utils\analytics\cli.py", line 66, in publisher_wrapper
    return fn(*args, **kwargs)
  File "C:\Users\marce\AppData\Local\Programs\Python\Python310\lib\site-packages\localstack_ext\cli\extensions.py", line 24, in cmd_extensions_install
    def cmd_extensions_install(name):from localstack import config as A;from localstack_ext.bootstrap.extensions import repository as B;assert_venv_initialized();C=os.path.join(A.Directories.for_container().var_libs,B.VENV_DIRECTORY,_E);_run_localstack_container_command([C,'-m','pip',_F,name])
  File "C:\Users\marce\AppData\Local\Programs\Python\Python310\lib\site-packages\localstack_ext\cli\extensions.py", line 61, in _run_localstack_container_command
    from localstack import config as D,constants as B;from localstack.utils import docker_utils as A;C=A.DOCKER_CLIENT.create_container(image_name=B.DOCKER_IMAGE_NAME_PRO,entrypoint='',remove=_B,command=cmd,mount_volumes=[(D.VOLUME_DIR,B.DEFAULT_VOLUME_DIR)]);A.DOCKER_CLIENT.start_container(C);E=A.DOCKER_CLIENT.stream_container_logs(C)
  File "C:\Users\marce\AppData\Local\Programs\Python\Python310\lib\site-packages\localstack\utils\container_utils\docker_cmd_client.py", line 642, in start_container
    return self._run_async_cmd(cmd, stdin, container_name_or_id)
  File "C:\Users\marce\AppData\Local\Programs\Python\Python310\lib\site-packages\localstack\utils\container_utils\docker_cmd_client.py", line 675, in _run_async_cmd
    raise ContainerException(
localstack.utils.container_utils.container_client.ContainerException: ('Docker process returned with errorcode 1', b'', b'Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "/var/lib/localstack/lib\\\\extensions/python_venv\\\\bin/python": stat /var/lib/localstack/lib\\extensions/python_venv\\bin/python: no such file or directory: unknown\nError: failed to start containers: b237ebd94f05a7204601cca7a314c7db9ca3954989c73610271d891d803a0259\n')
'subdirectory' is not recognized as an internal or external command,
operable program or batch file.

License mismatch in PyPI

I tried installing localstack version 1.0.4 from PyPI at work, however, it's blocked due to the license of package localstack-ext being listed as "Other/Proprietary License (Proprietary)" on PyPI (https://pypi.org/project/localstack-ext/#description)

Within Github, it looks like the license is actually Apache 2.0, which my work would accept. Is there any possibility PyPI could have the license listed for this package updated to Apache 2.0 as well?

create extensions that records AWS requests into JSON files in the data directory

The goal of this extension is to demonstrate how you can intercept requests and response and do something with them.

a request/response format could look like this:

{
  "request": {
    "service": "sqs",
    "operation": "CreateQueue",
    "payload": {
      "QueueName": "my-queue"
    }
  },
  "response": {
    "status_code": 200,
    "payload": {
      "QueueUrl": "http://localhost:4566/000000000000/my-queue"
    }
  }
}

we could write each request/response doc into an NDJSON file.

to achieve this we need to:

  • use the def update_response_handlers(self, handlers: CompositeResponseHandler): extension method to inject a new response handler
  • that response handler needs to access context.service, context.operation, context.service_request (if it exists), context.service_response (if it exists)`
  • create the request/response JSON
  • append it to a file

Improve usage workflow when user isn't logged in

From CapitalOne customer

Brandon Atkinson
6:31 AM
Hey Chad, trying to get the extension installed, however my LocalStack CLI is giving me No such command 'extensions' when I try to install it. I did do a localstack update localstack-cli command which ran successfully. I'm on version 2.2.0 of the CLI.

Brandon Atkinson
6:40 AM
OK, nevermind
6:40
I had to login via the CLI first, now I have access to that command. Maybe that is an opportunity to update the error message?

Error when starting `localstack` with bootstrapped extension

Hi! I'm experimenting a bit with localstack extensions. My goal is, if I see a fit, develop an extension to mimic CloudWatch data.

I followed the instruction for creating the extension boilerplate, that works just fine. However, when attempting to start localstack with the extension enabled, that is:

EXTENSION_DEV_MODE=1 localstack start

I'm getting the following errors:

[17:28:35] starting LocalStack in Docker mode ๐Ÿณ                                                                                           localstack.py:138
Traceback (most recent call last):
  File "/Users/pablo/work/experiments/local-stack-tests/cloudwatch-metrics-emulator/.venv/bin/localstack", line 23, in <module>
    main()
  File "/Users/pablo/work/experiments/local-stack-tests/cloudwatch-metrics-emulator/.venv/bin/localstack", line 19, in main
    main.main()
  File "/Users/pablo/work/experiments/local-stack-tests/cloudwatch-metrics-emulator/.venv/lib/python3.10/site-packages/localstack/cli/main.py", line 11, in main
    cli()
  File "/Users/pablo/work/experiments/local-stack-tests/cloudwatch-metrics-emulator/.venv/lib/python3.10/site-packages/localstack/cli/plugin.py", line 15, in __call__
    self.group(*args, **kwargs)
  File "/Users/pablo/work/experiments/local-stack-tests/cloudwatch-metrics-emulator/.venv/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/Users/pablo/work/experiments/local-stack-tests/cloudwatch-metrics-emulator/.venv/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/Users/pablo/work/experiments/local-stack-tests/cloudwatch-metrics-emulator/.venv/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/pablo/work/experiments/local-stack-tests/cloudwatch-metrics-emulator/.venv/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/pablo/work/experiments/local-stack-tests/cloudwatch-metrics-emulator/.venv/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/Users/pablo/work/experiments/local-stack-tests/cloudwatch-metrics-emulator/.venv/lib/python3.10/site-packages/localstack/utils/analytics/cli.py", line 66, in publisher_wrapper
    return fn(*args, **kwargs)
  File "/Users/pablo/work/experiments/local-stack-tests/cloudwatch-metrics-emulator/.venv/lib/python3.10/site-packages/localstack/cli/localstack.py", line 140, in cmd_start
    bootstrap.prepare_host(console)
  File "/Users/pablo/work/experiments/local-stack-tests/cloudwatch-metrics-emulator/.venv/lib/python3.10/site-packages/localstack/utils/bootstrap.py", line 77, in wrapped
    return f(*args, **kwargs)
  File "/Users/pablo/work/experiments/local-stack-tests/cloudwatch-metrics-emulator/.venv/lib/python3.10/site-packages/localstack/utils/bootstrap.py", line 625, in prepare_host
    hooks.prepare_host.run()
  File "/Users/pablo/work/experiments/local-stack-tests/cloudwatch-metrics-emulator/.venv/lib/python3.10/site-packages/localstack/runtime/hooks.py", line 63, in run_in_order
    fn_plugin(*args, **kwargs)
  File "/Users/pablo/work/experiments/local-stack-tests/cloudwatch-metrics-emulator/.venv/lib/python3.10/site-packages/plugin/core.py", line 183, in __call__
    return self.fn(*args, **kwargs)
  File "/Users/pablo/work/experiments/local-stack-tests/cloudwatch-metrics-emulator/.venv/lib/python3.10/site-packages/localstack_ext/extensions/plugins.py", line 14, in configure_extensions_dev_host
    def configure_extensions_dev_host():from localstack_ext.extensions.bootstrap import run_on_configure_host_hook as A;A()
ModuleNotFoundError: No module named 'localstack_ext.extensions.bootstrap'

Any ideas? Just in case it helps, here's a pip freeze:

(.venv) โžœ  cloudwatch-metrics-emulator pip freeze
apispec==6.3.0
boto3==1.26.100
botocore==1.29.100
cachetools==5.0.0
certifi==2022.12.7
cffi==1.15.1
charset-normalizer==3.1.0
click==8.1.3
# Editable install with no version control (cloudwatch-metrics-emulator==0.0.1)
-e /Users/pablo/work/experiments/local-stack-tests/cloudwatch-metrics-emulator
cryptography==40.0.1
dill==0.3.2
dnslib==0.9.23
dnspython==2.3.0
ecdsa==0.18.0
idna==3.4
jmespath==1.0.1
localstack==1.4.0
localstack-client==2.0
localstack-ext==1.4.0
markdown-it-py==2.2.0
mdurl==0.1.2
packaging==23.0
pbr==5.11.1
plux==1.3.1
psutil==5.9.4
pyaes==1.6.1
pyasn1==0.4.8
pycparser==2.21
Pygments==2.14.0
python-dateutil==2.8.2
python-dotenv==1.0.0
python-jose==3.3.0
PyYAML==6.0
requests==2.28.2
rich==13.3.3
rsa==4.9
s3transfer==0.6.0
semver==2.13.0
six==1.16.0
stevedore==5.0.0
tabulate==0.9.0
tailer==0.4.1
urllib3==1.26.15

AWS Replicator: Error: No such command 'replicate'

Hi, just followed the guide to the T.

After installing the aws-replicator extension and i lunch the command localstack aws replicate -s sqs

i receive the following error:

Usage: localstack aws [OPTIONS] COMMAND [ARGS]...
Try 'localstack aws -h' for help.

Error: No such command 'replicate'.

And when going to check the content of available commands for aws i get only this

Usage: localstack aws [OPTIONS] COMMAND [ARGS]...

  Accesses additional functionality on LocalStack emulated AWS services.

  This command provides tools to enhance your experience with certain emulated
  AWS services.

Options:
  -h, --help  Show this message and exit.

Commands:
  iam  (Beta) Access LocalStack IAM features

I am using a trial version of the Pro, LocalStack CLI 3.4.0

localstack status output

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Runtime version โ”‚ 3.4.1.dev                                             โ”‚
โ”‚ Docker image    โ”‚ tag: latest, id: 4b87860f7f42, ๐Ÿ“† 2024-05-06T13:49:55 โ”‚
โ”‚ Runtime status  โ”‚ โœ” running (name: "localstack-main", IP: 172.17.0.2)   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Add ability to list installed extensions

Currently there is not a way to list installed extensions.

To recreate

localstack extensions install <extension>
# no way to list the extensions so `uninstall` is easier

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.