redocmx


Nameredocmx JSON
Version 0.0.2 PyPI version JSON
download
home_pagehttps://github.com/redocmx/client-python
SummaryConversión CFDI a PDF
upload_time2024-04-02 20:29:09
maintainerNone
docs_urlNone
authorredoc.mx
requires_python>=3.6
licenseMIT
keywords cfdi a pdf cfdi cfdi to pdf conversión cfdi a pdf sat mexico mexico
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Converting CFDI to PDF

## redocmx

The `redocmx` module is a Python client for interacting with the [redoc.mx](https://redoc.mx) REST API to convert CFDIs (Comprobante Fiscal Digital por Internet) to PDFs. 

This client simplifies the process of sending XML data and retrieving the converted PDF, along with transaction details and metadata. 

This package is synchronous.

## Installation

To install the module, run:

```bash
pip install redocmx
```

## Usage

First, import the module and create an instance of the Redoc client. 

You can optionally pass your API key as an argument, or the client will attempt to load it from the REDOC_API_KEY environment variable.

```python
from redocmx import RedocmxClient

redoc =  RedocmxClient('your_api_key_here')
```

### Converting CFDI to PDF

The `redocmx` provides two options for loading CFDI data: from a file or directly from a string.

#### Option 1: Load XML from the File System

```python
cfdi = redoc.cfdi.from_file('./path/to/your/file.xml')
```

#### Option 2: Use an XML Content String

```python
cfdi = redoc.cfdi.from_string('<xml_content_string_here>');
```

### Generating the PDF

To convert the loaded CFDI to a PDF:

```python
try:
	pdf = cfdi.to_pdf()
	
	with open('./nomina.pdf', 'wb') as pdf_file:
		pdf_file.write(pdf.to_buffer())

	print(f"Transaction ID: {pdf.get_transaction_id()}")
	print(f"Total Pages: {pdf.get_total_pages()}")
	print(f"Total Time: {pdf.get_total_time_ms()} ms")
	print(f"Metadata: {pdf.get_metadata()}")
		
except:
	print("An error occurred during the conversion")
```

## Examples

- [Basic example](https://github.com/redocmx/cfdi-a-pdf-ejemplos)
- [Custom logo and colors](https://github.com/redocmx/cfdi-a-pdf-ejemplos)
- [Change language to English](https://github.com/redocmx/cfdi-a-pdf-ejemplos)
- [Add additional rich content](https://github.com/redocmx/cfdi-a-pdf-ejemplos)

## API Reference

### Redoc

The `redoc` object is an instance of `Redoc`, created using `RedocmxClient(api_key)`.

| Method     | Description |
| -------- | ------- |
| redoc.cfdi.**from_file(file_path)**  |  Returns: **Cfdi** - **Instance**<br>Loads file content from the file system for converting a CFDI to PDF. The file should be valid XML for a CFDI.<br>It returns an instance of the Cfdi class, which can be used to obtain the PDF.|
| redoc.cfdi.**from_string(file_content)**  |  Returns: **Cfdi** - **Instance**<br>Uses a CFDI as a string for converting the CFDI to PDF. The string should be valid XML for a CFDI.<br>It returns an instance of the Cfdi class, which can be used to obtain the PDF.|

### Cfdi

The `cfdi` object is an instance of `Cfdi`, created using `redoc.cfdi.from_file(file_path)` or `redoc.cfdi.from_string(file_content)`.

| Method     | Description |
| -------- | ------- |
| cfdi.**set_addenda(str)**  |  Params: **String**<br>Allows the use of a [redoc addenda](https://redoc.mx/docs/addenda) for full control over the design of the final PDF.|
| cfdi.**to_pdf(options)**  |  Params: **Dictionary** - [PdfOptions](#pdfoptions)<br>Returns: **Pdf** - **Instance**<br>An instance of the Pdf class, which, when invoked, converts the CFDI into a PDF and stores it, along with the generated data from the conversion request.|

##### PdfOptions
```python
{
    "style_pdf": "John"
}
```
### Pdf

The `pdf` object is an instance of `Pdf`, created from `cfdi.to_pdf(options)`.

| Method     | Description |
| -------- | ------- |
| pdf.**to_buffer()**  |  Returns: **Buffer**<br>The PDF document as a buffer, ready for storage in the file system or to be sent back in an HTTP request.|
| pdf.**get_transaction_id()**  |  Returns: **String - UUID**<br>A unique ID for the transaction request to the redoc service.|
| pdf.**get_total_pages()** | Returns: **Integer**<br>The total number of pages generated for the PDF file. |
| pdf.**get_total_time_ms()**    | Returns: **Integer**<br>Time in milliseconds taken to convert the CFDI to PDF. |
| pdf.**get_metadata()**    | Returns: **Dictionary** - [CfdiMetadata]()<br>General information from the converted CFDI. |

##### CfdiMetadata
```js 
{
    TDB...
}
```

## Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue for any bugs, features, or improvements.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/redocmx/client-python",
    "name": "redocmx",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "cfdi a pdf, cfdi, cfdi to pdf, conversi\u00f3n cfdi a pdf, sat mexico, mexico",
    "author": "redoc.mx",
    "author_email": "soporte@redoc.mx",
    "download_url": "https://files.pythonhosted.org/packages/11/76/5d2c89f104f67e52671b0a2cafe39d656c51d07c0a96105fd3a57ba095eb/redocmx-0.0.2.tar.gz",
    "platform": null,
    "description": "# Converting CFDI to PDF\n\n## redocmx\n\nThe `redocmx` module is a Python client for interacting with the [redoc.mx](https://redoc.mx) REST API to convert CFDIs (Comprobante Fiscal Digital por Internet) to PDFs. \n\nThis client simplifies the process of sending XML data and retrieving the converted PDF, along with transaction details and metadata. \n\nThis package is synchronous.\n\n## Installation\n\nTo install the module, run:\n\n```bash\npip install redocmx\n```\n\n## Usage\n\nFirst, import the module and create an instance of the Redoc client. \n\nYou can optionally pass your API key as an argument, or the client will attempt to load it from the REDOC_API_KEY environment variable.\n\n```python\nfrom redocmx import RedocmxClient\n\nredoc =  RedocmxClient('your_api_key_here')\n```\n\n### Converting CFDI to PDF\n\nThe `redocmx` provides two options for loading CFDI data: from a file or directly from a string.\n\n#### Option 1: Load XML from the File System\n\n```python\ncfdi = redoc.cfdi.from_file('./path/to/your/file.xml')\n```\n\n#### Option 2: Use an XML Content String\n\n```python\ncfdi = redoc.cfdi.from_string('<xml_content_string_here>');\n```\n\n### Generating the PDF\n\nTo convert the loaded CFDI to a PDF:\n\n```python\ntry:\n\tpdf = cfdi.to_pdf()\n\t\n\twith open('./nomina.pdf', 'wb') as pdf_file:\n\t\tpdf_file.write(pdf.to_buffer())\n\n\tprint(f\"Transaction ID: {pdf.get_transaction_id()}\")\n\tprint(f\"Total Pages: {pdf.get_total_pages()}\")\n\tprint(f\"Total Time: {pdf.get_total_time_ms()} ms\")\n\tprint(f\"Metadata: {pdf.get_metadata()}\")\n\t\t\nexcept:\n\tprint(\"An error occurred during the conversion\")\n```\n\n## Examples\n\n- [Basic example](https://github.com/redocmx/cfdi-a-pdf-ejemplos)\n- [Custom logo and colors](https://github.com/redocmx/cfdi-a-pdf-ejemplos)\n- [Change language to English](https://github.com/redocmx/cfdi-a-pdf-ejemplos)\n- [Add additional rich content](https://github.com/redocmx/cfdi-a-pdf-ejemplos)\n\n## API Reference\n\n### Redoc\n\nThe `redoc` object is an instance of `Redoc`, created using `RedocmxClient(api_key)`.\n\n| Method     | Description |\n| -------- | ------- |\n| redoc.cfdi.**from_file(file_path)**  |  Returns: **Cfdi** - **Instance**<br>Loads file content from the file system for converting a CFDI to PDF. The file should be valid XML for a CFDI.<br>It returns an instance of the Cfdi class, which can be used to obtain the PDF.|\n| redoc.cfdi.**from_string(file_content)**  |  Returns: **Cfdi** - **Instance**<br>Uses a CFDI as a string for converting the CFDI to PDF. The string should be valid XML for a CFDI.<br>It returns an instance of the Cfdi class, which can be used to obtain the PDF.|\n\n### Cfdi\n\nThe `cfdi` object is an instance of `Cfdi`, created using `redoc.cfdi.from_file(file_path)` or `redoc.cfdi.from_string(file_content)`.\n\n| Method     | Description |\n| -------- | ------- |\n| cfdi.**set_addenda(str)**  |  Params: **String**<br>Allows the use of a [redoc addenda](https://redoc.mx/docs/addenda) for full control over the design of the final PDF.|\n| cfdi.**to_pdf(options)**  |  Params: **Dictionary** - [PdfOptions](#pdfoptions)<br>Returns: **Pdf** - **Instance**<br>An instance of the Pdf class, which, when invoked, converts the CFDI into a PDF and stores it, along with the generated data from the conversion request.|\n\n##### PdfOptions\n```python\n{\n    \"style_pdf\": \"John\"\n}\n```\n### Pdf\n\nThe `pdf` object is an instance of `Pdf`, created from `cfdi.to_pdf(options)`.\n\n| Method     | Description |\n| -------- | ------- |\n| pdf.**to_buffer()**  |  Returns: **Buffer**<br>The PDF document as a buffer, ready for storage in the file system or to be sent back in an HTTP request.|\n| pdf.**get_transaction_id()**  |  Returns: **String - UUID**<br>A unique ID for the transaction request to the redoc service.|\n| pdf.**get_total_pages()** | Returns: **Integer**<br>The total number of pages generated for the PDF file. |\n| pdf.**get_total_time_ms()**    | Returns: **Integer**<br>Time in milliseconds taken to convert the CFDI to PDF. |\n| pdf.**get_metadata()**    | Returns: **Dictionary** - [CfdiMetadata]()<br>General information from the converted CFDI. |\n\n##### CfdiMetadata\n```js \n{\n    TDB...\n}\n```\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a pull request or open an issue for any bugs, features, or improvements.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Conversi\u00f3n CFDI a PDF",
    "version": "0.0.2",
    "project_urls": {
        "Homepage": "https://github.com/redocmx/client-python"
    },
    "split_keywords": [
        "cfdi a pdf",
        " cfdi",
        " cfdi to pdf",
        " conversi\u00f3n cfdi a pdf",
        " sat mexico",
        " mexico"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1c6edd054326aadb4be6d4d4038daa67932e228e0a41e45360cf412c8d792cb0",
                "md5": "36a095b0a379d395956effa564988f3d",
                "sha256": "6aa0e6b8e7817e4ac11623d9353e39cb4886d9ae661a7b4f94b9a08eaebe7e4d"
            },
            "downloads": -1,
            "filename": "redocmx-0.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "36a095b0a379d395956effa564988f3d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 6836,
            "upload_time": "2024-04-02T20:29:07",
            "upload_time_iso_8601": "2024-04-02T20:29:07.666118Z",
            "url": "https://files.pythonhosted.org/packages/1c/6e/dd054326aadb4be6d4d4038daa67932e228e0a41e45360cf412c8d792cb0/redocmx-0.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "11765d2c89f104f67e52671b0a2cafe39d656c51d07c0a96105fd3a57ba095eb",
                "md5": "641a4a2c0a06e199dc6c863f3170cfff",
                "sha256": "a51b3d3c6fbc7c0b0a452de969d8df8c1c11309fd157fb876e0d87582493610b"
            },
            "downloads": -1,
            "filename": "redocmx-0.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "641a4a2c0a06e199dc6c863f3170cfff",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 5792,
            "upload_time": "2024-04-02T20:29:09",
            "upload_time_iso_8601": "2024-04-02T20:29:09.247464Z",
            "url": "https://files.pythonhosted.org/packages/11/76/5d2c89f104f67e52671b0a2cafe39d656c51d07c0a96105fd3a57ba095eb/redocmx-0.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-02 20:29:09",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "redocmx",
    "github_project": "client-python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "redocmx"
}
        
Elapsed time: 0.22298s