Skip to main content

Read inline files stored inside another file.

Project description

Inline Files

This Python package allows us to read and interact with inline files.

An inline file is a file stored within another file. This parent file can be any kind of file, but a .py file is preferred due to how an inline file is defined.

Definition

We use the following syntax to define an inline file:

r"""ILF
__ID1__
Hello World!
__ID2:json__
{
    "hello": "world"
}
"""

In other words, an inline file must be defined inside a multiline comment, or docstring, and must be preceded by __[ID]__, where [ID] is the inline file's name. In the example above, there are two inline files, "ID1" and "ID2", with "ID2" having an optional extension.

If an inline file is defined with an extension, the file will be read according to that extension. For example, a JSON file will be processed using the json module. Files without an extension are treated as text files. Currently, the module supports json, yaml and xml extensions. Below is another example of an inline file with an extension.

r"""ILF
__file1:yaml__
filename: file1
extension: yaml

Module

The module contains a constructor responsible for reading a file and extracting its inline files. By default, this file will be the file that calls the constructor, but another file can be specified.

The module's main method, get_file(), will return an inline file's contents, which can be a string or a structure, if the file has one of the supported extensions.

There is also a get_extension() method, used to retrieve an inline file's extension.

Usage example

from inline_files import InlineFiles

ilf = InlineFiles()

i = ilf.get_file("ID1")

print(i)

r"""ILF
__ID1__
Hello World!
__ID2__
def ping():
    return "pong"
"""

Usage example with extensions

from inline_files import InlineFiles

ilf = InlineFiles()

j = ilf.get_json("J")

print(j["filename"])

r"""ILF
__J:json__
{
    "filename": "J",
    "extension": "json"
}
"""

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

inline_files-1.0.0.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

inline_files-1.0.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file inline_files-1.0.0.tar.gz.

File metadata

  • Download URL: inline_files-1.0.0.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.28.0

File hashes

Hashes for inline_files-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b98683dcb03addb5b447a8a2afda8b3dd22d249413fc63cef3b5b89cddfad1fa
MD5 39d0e2d6421673d0ba60f1c5e6f5928b
BLAKE2b-256 8477c2bc55ee91ce018e2ca779023e5cea4ebf0da262ab79f799b1482197f4d0

See more details on using hashes here.

File details

Details for the file inline_files-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: inline_files-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.28.0

File hashes

Hashes for inline_files-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 be54adf5f13e09834a4068af17b559c5c84bed9bd1034d9fcc03718983a5fae8
MD5 6c6bc9822e6cca6f9d919e275e465fd5
BLAKE2b-256 9bc48090116aab05b981643b0a67095c5b3b5a46e268876ba41b7b2035a6da56

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page