{"id":16419662,"url":"https://github.com/abhishek-ram/pyas2-lib","last_synced_at":"2025-04-09T13:03:04.946Z","repository":{"id":39847186,"uuid":"70227677","full_name":"abhishek-ram/pyas2-lib","owner":"abhishek-ram","description":"AS2 Library for building and parsing Messages and MDNs","archived":false,"fork":false,"pushed_at":"2025-03-22T14:08:38.000Z","size":365,"stargazers_count":45,"open_issues_count":7,"forks_count":32,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-02T11:56:53.620Z","etag":null,"topics":["as2","cms","compress","encrypt","sign","smime"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/abhishek-ram.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.md","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-10-07T08:17:54.000Z","updated_at":"2025-03-22T13:56:13.000Z","dependencies_parsed_at":"2023-11-29T18:28:36.028Z","dependency_job_id":"bf52b711-9aa5-4568-9341-fb3286dfe789","html_url":"https://github.com/abhishek-ram/pyas2-lib","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhishek-ram%2Fpyas2-lib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhishek-ram%2Fpyas2-lib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhishek-ram%2Fpyas2-lib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhishek-ram%2Fpyas2-lib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/abhishek-ram","download_url":"https://codeload.github.com/abhishek-ram/pyas2-lib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248045230,"owners_count":21038553,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["as2","cms","compress","encrypt","sign","smime"],"created_at":"2024-10-11T07:25:29.861Z","updated_at":"2025-04-09T13:03:04.929Z","avatar_url":"https://github.com/abhishek-ram.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pyas2-lib\n\n[![pypi package](https://img.shields.io/pypi/v/pyas2lib.svg)](https://pypi.python.org/pypi/pyas2lib/)\n[![Run Tests](https://github.com/abhishek-ram/pyas2-lib/actions/workflows/run-tests.yml/badge.svg?branch=master\u0026event=push)](https://github.com/abhishek-ram/pyas2-lib/actions/workflows/run-tests.yml?query=branch%3Amaster++)\n[![codecov](https://codecov.io/gh/abhishek-ram/pyas2-lib/branch/master/graph/badge.svg)](https://codecov.io/gh/abhishek-ram/pyas2-lib)\n\nA pure python library for building and parsing message as part of the AS2 messaging protocol. The message definitions follow the AS2 version 1.2 as defined in the [RFC 4130][1].The library is intended to decouple the message construction/deconstruction from the web server/client implementation. The following functionality is part of this library:\n   \n* Compress, Sign and Encrypt the payload to be transmitted.\n* Building the MIME Message from the processed payload.\n* Building a signed MDN Messages for a received payload.\n* Parsing a received MIME data and identifying if it as a Message or MDN. \n* Decompress, Decrypt and Verify Signature of the received payload.\n* Verify Signature of the received MDN and extract original message status. \n\n\n## Basic Usage\n\nLet us take a look at how we can use this library for building and parsing of AS2 Messages. \n\n### Setup\n\n* First we would need to setup an organization and a partner\n```python\nfrom pyas2lib.as2 import Organization, Partner\n\nmy_org = Organization(\n    as2_name='my_unique_id',  # Unique AS2 Id for this organization\n    sign_key=b'signature_key_bytes',  # PEM/DER encoded private key for signature\n    sign_key_pass='password',  # Password private key for signature\n    decrypt_key=b'decrypt_key_bytes',  # PEM/DER encoded private key for decryption\n    decrypt_key_pass='password'  # Password private key for decryption\n)\n\na_partner = Partner(\n    as2_name='partner_unique_id',  # Unique AS2 Id of your partner\n    sign=True,  # Set to true for signing the message\n    verify_cert=b'verify_cert_bytes',  # PEM/DER encoded certificate for verifying partner signatures\n    encrypt=True,  # Set to true for encrypting the message\n    encrypt_cert=b'encrypt_cert_bytes',  # PEM/DER encoded certificate for encrypting messages\n    mdn_mode='SYNC',  # Expect to receive synchronous MDNs from this partner\n    mdn_digest_alg='sha256'  # Expect signed MDNs to be returned by this partner\n)\n\n``` \n\n### Sending a message to your partner\n\n* The partner is now setup we can build an AS2 message\n```python\nfrom pyas2lib.as2 import Message\n\nmsg = Message(sender=my_org, receiver=a_partner)\nmsg.build(b'data_to_transmit')\n\n```\n* The message is built and now `msg.content` holds the message body and `message.header` dictionary holds the message headers. These need to be passed to any http library for HTTP POSTing to the partner.\n* We expect synchronous MDNs so we need to process the response to our HTTP POST\n```python\nfrom pyas2lib.as2 import Mdn\n\nmsg_mdn = Mdn()  # Initialize an Mdn object\n\n# Call the parse method with the HTTP response headers + content and a function that returns the related `pyas2lib.as2.Messsage` object.\nstatus, detailed_status = msg_mdn.parse(b'response_data_with_headers', find_message_func)\n```\n* We parse the response mdn to get the status and detailed status of the message that was transmitted.\n\n### Receiving a message from your partner\n\n* We need to setup and HTTP server with an endpoint for receiving POST requests fro your partner.\n* When a requests is received we need to first check if this is an Async MDN\n```python\nfrom pyas2lib.as2 import Mdn\n\nmsg_mdn = Mdn()  # Initialize an Mdn object\n# Call the parse method with the HTTP request headers + content and a function the returns the related `pyas2lib.as2.Messsage` object.\nstatus, detailed_status = msg_mdn.parse(request_body, find_message_fumc)\n```\n* If this is an Async MDN it will return the status of the original message.\n* In case the request is not an MDN then `pyas2lib.exceptions.MDNNotFound` is raised, which needs to be catched and parse the request as a message.\n```python\nfrom pyas2lib.as2 import Message\n\nmsg = Message()\n# Call the parse method with the HTTP request headers + content, a function to return the the related `pyas2lib.as2.Organization` object, a function to return the `pyas2lib.as2.Partner` object and a function to check for duplicates.\nstatus, exception, mdn = msg.parse(\n    request_body, find_organization, find_partner, check_duplicate_msg)\n```\n* The parse function returns a 3 element tuple; the status of parsing, exception if any raised during parsing and an `pyas2lib.as2.Mdn` object for the message.\n* If the `mdn.mdn_mode` is `SYNC` then the `mdn.content` and `mdn.header` must be returned in the response.\n* If the `mdn.mdn_mode` is `ASYNC` then the mdn must be saved for later processing.  \n\n## Contribute\n\n1. Check for open issues or open a fresh issue to start a discussion around a feature idea or a bug.\n1. Fork [the repository][2] on GitHub to start making your changes to the **master** branch (or branch off of it).\n1. Create your feature branch: `git checkout -b my-new-feature`\n1. Commit your changes: `git commit -am 'Add some feature'`\n1. Push to the branch: `git push origin my-new-feature`\n1. Send a pull request and bug the maintainer until it gets merged and published. :) Make sure to add yourself to [AUTHORS][3].\n\n[1]: https://www.ietf.org/rfc/rfc4130.txt\n[2]: https://github.com/abhishek-ram/pyas2-lib\n[3]: https://github.com/abhishek-ram/pyas2-lib/blob/master/AUTHORS.md\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabhishek-ram%2Fpyas2-lib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabhishek-ram%2Fpyas2-lib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabhishek-ram%2Fpyas2-lib/lists"}