
Product
Secure Your AI-Generated Code with Socket MCP
Socket MCP brings real-time security checks to AI-generated code, helping developers catch risky dependencies before they enter the codebase.
A library for generating HTML pages on the server, allowing dynamic content updates from APIs while serving static files.
Static Site Generation (SSG) is a technique where HTML pages are generated on the server and served as static files. This allows for better initial performance and improved SEO optimization, as search engines can easily index the content. With SSG, applications provide a faster and smoother user experience, especially on mobile devices, making content delivery more efficient and accessible. The key advantage of SSG is that the pages can be dynamically updated with data from APIs while remaining static in nature.
Python-SSG is ideal for those who need to generate static pages that dynamically update with data from APIs. Here are some use cases:
To install the library, you can use the following command:
pip install python-ssg
Create a configuration file (config.json
):
The file should contain the following structure:
{
"pages": {
"index": {
"api": {
"url": "http://127.0.0.1:5000/api/index",
"method": "GET"
},
"render_interval": 5
}
}
}
Each page corresponds to an HTML template file in the /html/
directory, and the result is rendered in the /dist/
directory. The defined API returns JSON, which is used to populate the template. This JSON can come from local APIs, as in the example, or any external API you wish to use.
Start Rendering:
To start rendering, you should call the start_rendering
function and pass the path of your configuration file.
from python_ssg import start_rendering
if __name__ == "__main__":
start_rendering("config.json")
Here is an example directory structure for using the library:
your_project/
- config.json
- html/
- assets/
- (Your folders and files)
- index.html
- (Your HTML files)
- dist/
- (rendered HTML files)
- main.py
index.html
An example HTML file that uses variables for rendering:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="assets/style.css">
<title>{{ title }}</title>
</head>
<body>
<h1>{{ title }}</h1>
<p>{{ description }}</p>
<script src="assets/script.js"></script>
</body>
</html>
Feel free to explore, open issues, suggest pull requests, or just enjoy learning from the code!
A planned future improvement for the project is the possibility of integrating Python-SSG with AWS S3. This will allow the generated static pages to be automatically uploaded to a bucket on S3, keeping the site online and always updated with the latest content without the need to manage servers.
It’s not implemented yet, but it would be extremely useful for those looking to automate the update of static pages hosted in the cloud, keeping everything synchronized with real-time APIs.
To ensure that all library features are working correctly, it is important to run tests. You can do this using Python's unittest
module.
Follow the steps below to run the tests:
Navigate to the root directory of your project.
Execute the following command:
python -m unittest discover -s tests -p "*.py"
FAQs
A Python SSG library for dynamically generating static websites
We found that python-ssg demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket MCP brings real-time security checks to AI-generated code, helping developers catch risky dependencies before they enter the codebase.
Security News
As vulnerability data bottlenecks grow, the federal government is formally investigating NIST’s handling of the National Vulnerability Database.
Research
Security News
Socket’s Threat Research Team has uncovered 60 npm packages using post-install scripts to silently exfiltrate hostnames, IP addresses, DNS servers, and user directories to a Discord-controlled endpoint.